laravel controllers
Laravel Create Controller
To create a controller in laravel using PHP artisan command
open a terminal and write the following
php artisan make:controller ProfileController
you can replace the Profilecontroller with your controller name
you can find the new controller in app/Http/Controllers/ProfileController.php.
laravel CRUD controller
The full form of CRUD is to create, reads, update, delete, it's a stander way to manage yore data.
now to create a CRUD controller in laravel follow these steps:
step1: open terminals and run artisan command
php artisan make:controller ProfileController -r
this artisan command will create a Profilecontroller withe the basic curd method
- index - method should render a list of profile
- show - method show t a single profile
- create - method show a view to create a new profile
- store - method will handle and save a new profile
- edit - method show a view to edit profile
- update - method will update a specific profile
- destroy - method will destroy a specific profile
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProfileController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
How to call a specific controller method
open the app/routs/web.php where you can register web routes for your application.
add the following code
Route::get('/profile', 'ProfileController@index');
now when the user request equal to the /profile then the index method will trigger