0% found this document useful (0 votes)
24 views2 pages

Laravel RESTful Controller Guide

This document outlines the basic RESTful routes for performing CRUD operations in a Laravel application. It describes controllers for saving data to a database via store(), retrieving all data via index(), creating an individual page via create(), and editing data via edit() and update(). These controllers handle validation, querying the database, and passing data between views.

Uploaded by

Marckhycs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Laravel RESTful Controller Guide

This document outlines the basic RESTful routes for performing CRUD operations in a Laravel application. It describes controllers for saving data to a database via store(), retrieving all data via index(), creating an individual page via create(), and editing data via edit() and update(). These controllers handle validation, querying the database, and passing data between views.

Uploaded by

Marckhycs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

LARAVEL RESTFUL

1. To save data to the data base:


======== CONTROLLER ========

1. public function store(){


2. //validation
3. $data = request()->validate([
4. ‘name’ => ‘required’,
5. ]);
6.  
7. //adding to the data base
8. \App\Model::create($data);
9. }

2. To retrieve data from the database:


======== CONTROLLER ========

1. public function index(){


2.
3. //getting the data from database
4. $data = \App\Model::all();
5.
6. //passing the data to view
7. return view(‘view’,compact(‘data’));
8. }

3. To create an individual page for users 

1. public function create(\App\Model $user){


2. return view(‘view’, compact(‘user’));
3. } 
4. To edit a user information

1. public function edit(){


2. return(‘view);
3. }
4.  
5.  
6. public function update(App\Model $user){
7. $data = request()-validate([
8. ‘name’ => ‘required’
9. ]);
10.  
11. $user -> update($data);
12. return view(‘view);
13. }

You might also like