der1der1 / laravel11.1_startup

startup prodecure
0 stars 0 forks source link

the begining for start up a project #1

Open der1der1 opened 3 months ago

der1der1 commented 3 months ago
    • "cd" get into the file i want to place
      laravel new [project name]

      *would be wait for a long time!!

    • get into the filefold
      php artisan install:api
    • would be wait for a long time!!
    • so the file : route/api.php will be exist!
    • 召喚api.php
  1. the cmd pannel will ask us
    One new database migration has been published. Would you like to run all pending database migrations? (yes/no) [yes]:
    #""YES"" !!
  2. 
    composer require laravel/sanctum

php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"

* After manually created a table.php (it contains sql command)
* plz delete all the other table.php (such as ~tocken.php)
```php
php artisan migrate
  1. get in Model/user.php and add follwing:

    use Laravel\Sanctum\HasApiTokens;
    class User extends Authenticatable{
    use HasApiTokens, HasFactory, Notifiable;
    }
    • to make the code corresponding! not adds directly!!
  2. get in routes/api.php and add follwing:

    Route::group(['middleware' => ['auth:sanctum']], function () {
    });
  3. found Model, Migration, & Controller

    php artisan make:model [project name] -rmc
    • [project name] such as: Animal.
  4. routes setting, get in routes/api.php and add follwing:

    
    use App\Http\Controllers\[controller name];

Route::apiResource('[project name]s', [controller name]::class);

* [project name] such as: Animal.
* [controller name] such as [AnimalController]
9. testing route. 
```php
php artisan route:list

it would show lots of infos being like:

  GET|HEAD        / ........................................................  
  GET|HEAD        api/animal ......... animal.index › AnimalController@index  
  POST            api/animal ......... animal.store › AnimalController@store  
  GET|HEAD        api/animal/{animal} .. animal.show › AnimalController@show  
  PUT|PATCH       api/animal/{animal} animal.update › AnimalController@upda…
  DELETE          api/animal/{animal} animal.destroy › AnimalController@des…
  GET|HEAD        api/user .................................................
  GET|HEAD        sanctum/csrf-cookie sanctum.csrf-cookie › Laravel\Sanctum…
  GET|HEAD        up .......................................................

10.

php artisan serve