Thứ Tư, 14 tháng 9, 2016

#Part3 laravel 5 Blog Tutorial : Restful Controllers & Routing System


Create Blog Apps in Laravel 5.3 - To continue or CRUD / create blog apps in laravel, this lesson will discuss about Restful Controllers & Routing System in Blog project.

at the previews lessons, we has create database and connect it form laravel project, if you still confused, just read #Part2 laravel 5 Blog Tutorial : Database & Migration.

Restful Controllers & Routing System
To create new Controllers in our Laravel Project, we use 'Artisan Command' :

php artisan make:controller BlogController --resource

--resource syntax mean, we will create a controller (BlogController.php) with fully configuration/function like the Index functions, Store function, Create function, Show function, Edit function, and more.

This is default our Controller

Restful Controllers & Routing System

BlogController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class BlogController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return IlluminateHttpResponse
     */
    public function index()
    {
        // 
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return IlluminateHttpResponse
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpResponse
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function destroy($id)
    {
        //
    }
}

Next, create new routes, we has discuss about routes, please read for more detail Routing Basics in Laravel.

Web.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

// we will ad new route into middleware group

Route::group(['middleware' => ['web']], function() {
  Route::resource('blog','BlogController');  
});

Video Tutorial Restful Controllers & Routing System



See you next Lessons...

Không có nhận xét nào:

Đăng nhận xét