Laravel allows you to quickly and easily set up controllers and routes so that you can interact with data in a RESTful way..
Create a Model and Database Table
Create a Model in the usual way (the
-m flag creates a migration for the model, allowing you to set up a new database table):
Amend the migration as necessary and run
php artisan migrate to set up the new table.
Create a Resourceful Controller
Create a controller using Artisan using the
This creates a new controller under
app/Http/Controllers, with stubbed out methods to allow interaction with the database table for this resource:
index(): Display a listing view for the resource
create(): Show the form for creating a new resource
store(): Store a newly created resource in storage
show(): Display the specified resource
edit(): Update the specified resource in storage
destroy(): Remove the specified resource from storage
Ruby on Rails has avery similar command:
rails g scaffold_controller Article - which stubs out a similar controller.
Create Route for the Resource
routes/web.php file (Laravel 5.3), create a new route using the
If you check the registered routes now using
php artisan route:list, you’ll see the new (named) routes automatically set up:
The resource has been set up so that the correct controller methods are triggered when you access a specified route with a given HTTP verb.
comments powered by Disqus