laravel 5.4 New Feature - Add eloquent whereKey method (ok)

https://www.itsolutionstuff.com/post/laravel-54-new-feature-add-eloquent-wherekey-methodexample.html

C:\xampp\htdocs\wpclidemo\app\Http\Controllers\HomeController.php

<?php
namespace App\Http\Controllers;
use App\Models\User;
use DB;
use Illuminate\Http\Request;
class HomeController extends Controller {
  /**
   * Create a new controller instance.
   *
   * @return void
   */
  public function __construct() {
    // $this->middleware('auth');
  }
  /**
   * Show the application dashboard.
   *
   * @return \Illuminate\Contracts\Support\Renderable
   */
  public function index() {
    return view('home');
  }
  public function test() {
    $tests = DB::table('pings')
    ->select(["id","name"])
    ->whereName("test123")
    ->get();
    return view('tests')->with(compact('tests'));
  }
}

C:\xampp\htdocs\wpclidemo\resources\views\tests.blade.php

C:\Users\Administrator\Downloads\pings (2).sql

laravel 5.4 New Feature - Add eloquent whereKey method

By Hardik Savani January 25, 2017 Category : LaravelPlayUnmuteLoaded: 1.20%FullscreenVDO.AI

Yesterday release Laravel 5.4 new version with new features and many upgrade. Laravel also provide documentation for Laravel 5.4 on their website. There are several update in Laravel 5.4 like in collections, mail, factory helper, Bootstrappers etc.

In this post we are going to see whereKey method in Laravel Eloquent. whereKey is very simple way to use and pretty interesting feature. laravel provide us where condition with add key(column) name and then value, But in this method you have write Key = name of column.

So i am going to give one example for whereKey() that way you can understand how it is working. So first we have on "posts" table with some dummy data like as bellow screen shot.

posts table

Ok, now we require to get only status = 'PUBLISHED' records. So now using whereKey() through we can make query as like bellow:

whereKey() Example

You will be found out put as like bellow:

Output:

Read Also: Laravel 5 - Full Text Search Example using Scout and Algolia Packages

I hope it can help you...

Last updated

Was this helpful?