Ejemplo n.º 1
0
<?php

get('/', ['middleware' => ['cache.fetch', 'cache.put'], 'uses' => 'HomeController@home']);
get('/articles/{slug}', ['as' => 'articles.show', 'uses' => 'HomeController@showArticle']);
get('/user/{username}/articles', ['middleware' => ['cache.fetch', 'cache.put'], 'uses' => function ($username) {
    return 'article of ' . $username;
}]);
get('auth/github', 'Auth\\AuthController@redirectToProvider');
get('auth/github/callback', 'Auth\\AuthController@handleProviderCallback');
Route::group(['middleware' => 'auth'], function () {
    get('auth/logout', function () {
        \Auth::logout();
        return redirect('/');
    });
    resource('posts', 'PostController');
});
get('test/search', function () {
    $keyword = \Request::get('keyword') || 'lorem';
    // Match any fields
    $posts = App\Post::search($keyword)->paginate();
    dd($posts);
    // Match all fields
    // Article::search($keyword, true)->paginate();
});
get('test/transaction', function () {
    \DB::transaction(function () {
        App\Post::findOrFail(8);
        $foo = App\Post::find(6)->delete();
    });
});
Ejemplo n.º 2
0
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => ['web']], function () {
    //
});
Route::group(['middleware' => 'web'], function () {
    Route::auth();
    Route::get('/home', 'HomeController@index');
});
Route::group(['namespace' => 'Posts'], function () {
    Route::pattern('posts', '[0-9]+');
    Route::resource('posts', 'PostsController');
});
Route::get('edit-post/{id}', function ($id) {
    // Let's just pretend we are logged in as the user with ID 1