My Blog Posts

Laravel API Artisan Command

Laravel API Artisan Command


resources:create Creates all the files you need to create an API resource

php artisan resources:create Post
 Checking Checking  if  the  model exists ...
The  model  Post does  not  exist.

Should I create it? (yes/no)[yes]:
 >
 Should I create the migration  for  Post? (yes/no)[yes]:
 >
 Should I create the factory  for  Post? (yes/no)[yes]:
 >
 Should I create the seeder  for  Post? (yes/no)[yes]:
 >

 Creating Creating  6  resources ...

The command creates the following files for you:

  • Controller
  • Form request
  • Resource and resource collection
  • Policy
  • Model
  • Database factory
  • Database migration
  • Database seeder
  • Routes

routes/api.php File added routes :

/*
|--------------------------------------------------------------------------
| Post endpoints
|--------------------------------------------------------------------------
 */
Route::name('posts.')->prefix('posts')->group(function () {
    Route::get('/', 'PostControllerAPI@index')->name('index');
    Route::post('/', 'PostControllerAPI@store')->name('create');
    Route::get('/{post}', 'PostControllerAPI@show')->name('show');
    Route::patch('/{post}', 'PostControllerAPI@update')->name('update');
    Route::delete('/{post}', 'PostControllerAPI@destroy')->name('destroy');
});

Click here to learn more about this package



Share this article


Comments (0)

Comment