Beispiel #1
0
    }
    public function addplus($value)
    {
        return $value + 10;
    }
    function getAA()
    {
    }
}
App::bind('BarInterface', function () {
    return new Bar();
});
Route::get('bar', function (BarInterface $bar, Request $request) {
    // \App\Article::create(['title'=>'new','body'=>'New body']);
    //App\Article::where('body','loren inpun')->get();
    return App\Article::where('body', 'loren inpun')->get();
});
Route::get('/', function () {
    return view('welcome');
});
Route::get('home', function () {
    return view('index');
});
Route::get('tagle', function () {
    if (Auth::check()) {
        $user = Auth::user();
        Auth::user()->articles()->save(new \App\Article());
        return $user;
    }
    return "sorry you should authorizaishen";
});
Beispiel #2
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for 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::bind('article', function ($slug) {
    return App\Article::where('slug', $slug)->first();
});
Route::get('/', ['as' => 'front', 'uses' => 'ArticleController@index']);
Route::get('/article/{article}', ['as' => 'show', 'uses' => 'ArticleController@show']);
Route::controllers(['auth' => 'Auth\\AuthController', 'password' => 'Auth\\PasswordController']);
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => 'auth'], function () {
    Route::get('/', ['as' => 'home', 'uses' => 'AdminHomeController@index']);
    Route::resource('article', 'AdminArticleController');
    Route::resource('category', 'AdminCategoryController');
});
Beispiel #3
0
 $articles = App\Article::where('id', '<', 3);
 $articles->update(array('body' => 'test'));
 return 'Mass update!';
 // updating a single article
 $article = App\Article::find(3);
 $article->title = 'How to drive a car';
 $article->save();
 return 'Saved! New title is: ' . $article->title;
 /*
 	RETRIEVING ARTICLES
 */
 // retieving a single article by ID
 $article = App\Article::find(3);
 return $article->title;
 // retrieving multiple articles (like with QueryBuilder)
 $articles = App\Article::where('id', '>', 1)->get();
 foreach ($articles as $art) {
     var_dump($art->title);
 }
 return $articles = App\Article::all();
 foreach ($articles as $art) {
     var_dump($art->title);
 }
 return;
 /*
 	CREATING NEW ARTICLES
 */
 $article3 = App\Article::create(array('title' => 'How to ride a bike', 'body' => '...'));
 return;
 // second way (never a mass-assignment alert if done this way)
 $article2 = new App\Article();