示例#1
0
文件: routes.php 项目: sirx/w0bm.com
| 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::get('/', ['as' => 'home', function () {
    Session::reflash();
    // Dummy query to calculate rows
    \App\Models\Video::selectRaw('SQL_CALC_FOUND_ROWS videos.*')->filtered()->limit(0)->first();
    // get actual count
    $id = \DB::select('SELECT FOUND_ROWS() c')[0]->c - 1;
    $id = mt_rand(0, $id);
    $video = \App\Models\Video::filtered()->skip($id)->first();
    return redirect($video->id);
}]);
Route::get('messages', 'MessageController@page');
Route::get('user/{username}', 'UserController@show');
Route::get('user/{username}/favs', 'UserController@show_favs');
Route::get('user/{username}/comments', 'UserController@show_comments');
Route::get('logout', 'UserController@logout');
Route::post('login', 'UserController@login');
Route::get('register', 'UserController@create');
Route::post('register', 'UserController@store');
Route::get('activate/{token}', 'UserController@activate');
Route::get('index', 'VideoController@index');
Route::post('index/{id}', 'VideoController@update');
Route::get('upload', 'VideoController@create');
Route::get('categories', 'CategoryController@index');
示例#2
0
文件: Video.php 项目: sirx/w0bm.com
 /**
  * @param bool $category
  * @return Video
  */
 public function getPrev($category = false)
 {
     if (!$category) {
         return Video::filtered()->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
     } else {
         return Video::whereCategoryId($this->category->id)->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
     }
 }