laravel where example

Example 1: laravel update from query

$affected = DB::table('users')
              ->where('id', 1)
              ->update(['votes' => 1]);

Example 2: laravel not in query

DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();

Example 3: laravel with and where

$projects = Project::whereHas('projectOffers', function ($offer) {
            $offer->where('teacher_id', "Ahmed");
            $offer->where('status_id', "Accepted");
        })->where('status_id', "inprogress")->get();

Example 4: DB::table('users')->get();

DB::select('SELECT * FROM users WHERE name = "'.Input::get('name').'"');

Tags:

Sql Example