Laravel    
 Nulls


  ?   ,    .      ,        -.   -? ,   ,      PHP,         .         .   ,     ,    .  :  Laravel,    .  Laravel,           "".     ,     .  ,   !  Laravel,     , ,     -.





Nulls

Laravel    








1. 







     :



   ;

Composer   Laravel;

  Laravel





  !



   



         - .    -,         .



 ,   " ",     -    .        ,       ,   " ".



         .


   Mac



    Mac,           . Laravel       Herd.      (https://herd.laravel.com/),  ,      .

  Mac       . Laravel    Herd.      https://herd.laravel.com (https://herd.laravel.com),       .


   Windows

    Windows-   Laragon,   .     ,   :



https://www.mamp.info/en/mamp-pro/windows/ (https://www.mamp.info/en/)

https://www.wampserver.com/ru/ (http://www.wampserver.com/en/)

https://www.apachefriends.org/ (https://www.apachefriends.org/)


   Ubuntu



     Ubuntu,    Xampp,       .   ,   ,       (https://operavps.com/docs/install-laravel-on-ubuntu/).



            Laravel (https://laravel.com/docs/10.x/installation),      ,      .



    ,       :



1.Apache  Nginx (-   )

2.MySQL (    )

3.PHP (       ).



        ,  !   ,          .   ,    ,          -!


Composer   Laravel

      Laravel  Composer (https://getcomposer.org/).       composer.json.


Composer

       Composer    ,  .       .


 Composer     

  Composer     .        ,      :

$ composer make pizza












       "".  ,       , ,    ?      :



{

"toppings" : [

"pepperoni", 

"ham", 

"bacon", 

"beef", 

"sausage"

];

}



   ,         'composer.json'   .    :



$ composer make pizza



!             !



Composer,  ,    ( ),     .

Composer  ,    Herd  Laragon;       ,       https://getcomposer.org/download/ (https://getcomposer.org/download/).


 Laravel



Laravel installer   ,       Laravel   .     Laravel     Laravel,   :



laravel new project-name



 project-name     .              Laravel.


   Laravel



    Herd  Laragon,   .

  Composer    Laravel Installer.     :



$ composer global require "laravel/installer"


 Laravel Installer



    Laravel,       :



$ laravel new folder_name



        ;  No starter kit, PHPUnit  No .        MySQL.












            folder_name.        cd folder_name,   :



$ php artisan serve



       http://localhost:8000/.     URL    Laravel.



:    Laravel Herd,    Laravel    .test. ,   https://folder_name.test    .



!        .  Laravel ,         .



    ,       Laravel.


  Laravel



   Laravel      :












  10 :



1.app

2. bootstrap

3. config

4.  

5. public

6. 

7. 

8. 

9. 

10. vendor



      ,         .



App

 ,       .        , ,     .



Bootstrap

     laravel (startup laravel).



Config

         .



Database

      ,      (seeders).



Public

  Public    ,   ,    .



Resources

      .    ,   .



Routes

       .



Storage

Laravel      ,   .



Test

    ,         .



Vendor

     .        (     ),       .



   composer.json file   ? ,       (  )   .     .env,      ,         .



    Laravel.      Laravel       .



 !     Laravel.        .






2.







       .        ,      ,           .


 

   ,      ,   ,    .



   ,   . , "    (),    ".  ,        .    URL- -, , site.com/graveyard,   ,     ,     .   : ",     ""?  ,      "graveyard".



    Laravel  :



<?php



Route::get('graveyard', function(){ 

echo '   !';

});



     "". ,    "get"  "graveyard",      "   !".


  Laravel



   Laravel    routes\web.php.          .



 ,      : POST, GET, PUT  DELETE.    :



<?php



Route::post('/zombie', function () {

echo "We want to create a new zombie";

});



Route::get('/zombie', function () {

echo 'We want to read or view a zombie';

});



Route::put('/zombie', function () {

echo "We want to update an existing zombie";

});



Route::delete('/zombie', function () { 

echo "We want to destroy a zombie";

});



   POST, GET, PUT  DELETE     RESTful,      :



POST:   (Create).

GET:      (Read).

PUT:   (Update).

DELETE:   (Delete).



    CRUD (Create, Read, Update, Delete).



      GET,    ,       :



<?php



Route::any('/zombie', function () {

echo "Any request from this zombie route";

});



!



,       ?      GET-.  site.com/zombie,    GET.     ?



!    HTML-,  :



<form method="POST" action="/zombie">

@csrf

@method('PATCH')



<input type="submit">

</form>



   submit        POST- site.com/zombie.



    @csrf    .    - ,   HTTP    PATCH.      Laravel,          .



  

,       () -!    :



<form method="POST" action="/zombie">

@csrf

@method(DELETE)

<input type="hidden" name="id" value="2">

<input type="submit" value="Destroy">

</form>



    "".       2, ,  ,    .



,   :



<?php

use Illuminate\Http\Request; 



Route::delete('/zombie', function(Request $request){

$id = $request->id; Zombie::destroy($id);

});



        2!      Request  Laravel,    .       ,      .



!       ,            .      .



   .         .


     



     ,  ,   :



Route::get('/zombie', function(){

echo 'Greetings from the Zombie Page!';

});



     ,     :



Route::get('/zombie', [ZombieController::class, 'index']);



  /zombie   index  ZombieController.



       .   ,     .


 



   .



,       site.com/zombie/5     :



Route::get('/zombie/{id}', function($id){

echo "You've encountered a zombie with ID: " . $id;

});



      ,          :



Route::get('/zombie/{id}', function($id){

$zombie = Zombie::find($id);

echo 'Name: ' . $zombie->name . '<br />';

echo 'Strength: ' . $zombie->strength . '<br />'; echo 'Health: ' . $zombie->health . '<br />';

});



,     ,        .   ,        .












3.







-    ,        .   Laravel,        .



   ?



 Laravel    PHP-,          .   Laravel Eloquent Model       .



 Zombie



,  ,  Zombie,      /app/Models/Zombie.php:



<?php



namespace App\Models;

use Illuminate\Database\Eloquent\Model; 



class Zombie extends Model {

protected $table = 'zombies';

}



   Laravel,   Zombie   zombies    .   zombies    :



zombies table










: Laravel    updated_at  created_at,   ,          .     .      timestamps(),    .



,          .        ,           .



,    ,         Eloquent.


Eloquent: ORM  Laravel



Eloquent, ORM (Object-Relational Mapper)  Laravel,       .     :



<?php

use App\Models\Zombie; 

Route::get('/zombie/{id}', function($id){

$zombie = Zombie::find($id);

echo 'Name: ' . $zombie->name . '<br />';

echo 'Strength: ' . $zombie->strength . '<br />'; echo 'Health: ' . $zombie->health . '<br />';

});



        Zombie,           .



 , ,  Zombie,      Zombie,    App\Models\Zombie.   ,   ,        .



  ,    .



       ,         .         :



<?php



Route::get('/admin/zombies/create', function(){

echo '<form method="POST" action="/admin/zombies/create">

<input type="text" name="name" placeholder="Name"><br>

<input type="text" name="strength" placeholder="Strength"><br>

<input type="text" name="health" placeholder="Health"><br>

<input type="hidden" name="_token" value="' .csrf_token() . '">

<input type="submit" value="Create New Zombie">

</form>';

});



      (site.com/admin/zombies/create)   .










      

site.com/admin/zombies/create POST-,     :



<?php



Route::post('/admin/zombies/create', function () {

//   

});



  :



<?php



use App\Models\Zombie;

use Illuminate\Http\Request;



Route::post('/admin/zombies/create', function(Request$request){



// instantiate a new zombie

$zombie = new Zombie();

$zombie->name = $request->name;

$zombie->strength = $request->strength;

$zombie->health = $request->health;

$zombie->save();



echo 'Zombie Created';

});



      :



: Johnny Bullet Holes

Strength: 

: 70



   'Zombie Created'.        .












,   ?   ,    ,   , Laravel     :



<?php



use App\Zombie;

use Illuminate\Http\Request;



Route::post('/admin/zombies/create', function(Request$request){



// instantiate a new zombie using posted data

$zombie = Zombie::create($request->all());



echo 'Zombie Created';

});



        'MassAssignmentException'.  ,        "",    .  Laravel     .



      ,       Zombie,  :



protected $fillable = ['name', 'strength', 'health'];



    :



<?php namespace App\Models;



use Illuminate\Database\Eloquent\Model; class Zombie extends Model {

protected $table = 'zombies';

protected $fillable = ['name', 'strength', 'health'];

}



,    ,          .



,      :



: Ted Manwalking

Strength: 

: 90



       :












Eloquent    , ,       .    ,       .








4. 









-   ,   Laravel       .



          .    ,  Eloquent  Laravel          .


 



    . ,       'posts'  'comments'.



  .      ,           .   .



       weapons:



 weapons:












    'zombie_id'.     'id'  Zombies.  ,     (Foreign Key), ,         .         Weapons  Zombies.



       ,   :










  ,    ""     2  ""     1.



        .     app/Models/Weapon.php:



<?php namespace App\Models;



use Illuminate\Database\Eloquent\Model; class Weapon extends Model {

protected $table = 'weapons';

}



    ,   ,     :




  .


   .

   ,     (https://www.litres.ru/book/nulls/laravel-gayd-po-vyzhivaniu-69850618/chitat-onlayn/)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


