示例#1
0
 function postCreate()
 {
     $movies = new \App\Movie();
     $movies->title = \Input::get('title');
     $movies->genre = \Input::get('genre');
     $movies->rating = \Input::get('rating');
     $movies->save();
     return "Record Updated";
 }
 function postCreate()
 {
     $movie = new \App\Movie();
     $movie->title = 'Akirachix';
     $movie->genre = 'awesome';
     $movie->rating = '5';
     $movie->save();
     return "Recordupdates";
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $movieNames = ['Star Wars 1', 'Star Wars 2', 'Star Wars 3', 'Batman', 'Godfather', 'Avatar'];
     foreach ($movieNames as $movieName) {
         $movie = new \App\Movie();
         $movie->name = $movieName;
         $movie->save();
     }
 }
 function postCreate()
 {
     $validator = \App\Movie::runValidator(\Input::all());
     if ($validator->fails()) {
         return \Redirect::back()->withErrors($validator)->withInput();
     }
     $movie = new \App\Movie();
     $movie->title = \Input::get('title');
     $movie->genre = \Input::get('genre');
     $movie->rating = \Input::get('rating');
     $movie->save();
     return \Redirect::to('movies');
 }
示例#5
0
    Route::post('movies/vote', function (Request $request) {
        $userId = \Auth::user()->id;
        $input = Input::all();
        $vote = App\Vote::where('movie_id', '=', $input['id'])->where('user_id', '=', $userId)->first();
        // invert the existing vote
        if (count($vote)) {
            if ($vote->vote_up) {
                $vote->vote_up = 0;
            } else {
                $vote->vote_up = 1;
            }
        } else {
            // dd('new');
            $vote = new App\Vote();
            $vote->user_id = $userId;
            $vote->movie_id = $input['id'];
            $vote->vote_up = 1;
        }
        if ($vote->save()) {
            return response()->json('success', 200);
        } else {
            return response()->json('error', 500);
        }
    });
    Route::get('movies', function () {
        $userId = \Auth::user()->id;
        return App\Movie::with(['votes' => function ($query) use($userId) {
            $query->where('user_id', $userId);
        }])->get();
    });
});
示例#6
0
文件: routes.php 项目: meneman/media
<?php

/*
|--------------------------------------------------------------------------
| Routes File
|--------------------------------------------------------------------------
|
| 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 () {
    App\Movie::create(['movie_name' => 'hansimglueck', 'year' => '1993']);
    $movies = App\Movie::all();
    foreach ($movies as $movie) {
        echo $movie->movie_name;
        var_dump($movie);
    }
    //var_dump($movies);
});
/*
|--------------------------------------------------------------------------
| 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.
|
*/