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. }