Get Specific Columns Using “With()” Function in Laravel Eloquent

Well I found the solution. It can be done one by passing a closure function in with() as second index of array like Post::query() ->with([‘user’ => function ($query) { $query->select(‘id’, ‘username’); }]) ->get() It will only select id and username from other table. I hope this will help others. Remember that the primary key (id … Read more

Facebook OAuth “The domain of this URL isn’t included in the app’s domain”

In case someone comes across this and is looking for these settings (like I was) You have to On the left hand side, click “+Add Product” and select “Facebook Login” (it was at the top for me) See the new settings available on the left hand side You will now have these OAuth settings on … Read more

Laravel 5 – artisan seed [ReflectionException] Class SongsTableSeeder does not exist

You need to put SongsTableSeeder into file SongsTableSeeder.php in the same directory where you have your DatabaseSeeder.php file. And you need to run in your console: composer dump-autoload to generate new class map and then run: php artisan db:seed I’ve just tested it. It is working without a problem in Laravel 5

How to Get the Current URL Inside @if Statement (Blade) in Laravel 4?

You can use: Request::url() to obtain the current URL, here is an example: @if(Request::url() === ‘your url here’) // code @endif Laravel offers a method to find out, whether the URL matches a pattern or not if (Request::is(‘admin/*’)) { // code } Check the related documentation to obtain different request information: http://laravel.com/docs/requests#request-information

Eloquent Collection: Counting and Detect Empty

When using ->get() you cannot simply use any of the below: if (empty($result)) { } if (!$result) { } if ($result) { } Because if you dd($result); you’ll notice an instance of Illuminate\Support\Collection is always returned, even when there are no results. Essentially what you’re checking is $a = new stdClass; if ($a) { … … Read more

How to use multiple databases in Laravel

Tested versions (Updated) Version Tested (Yes/No) 4.2 No 5.x Yes (5.5) 6.x No 7.x No 8.x Yes (8.4) 9.x Yes (9.2) Define Connections Using .env >= 5.0 (or higher) In .env DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=database1 DB_USERNAME=root DB_PASSWORD=secret DB_CONNECTION_SECOND=mysql DB_HOST_SECOND=127.0.0.1 DB_PORT_SECOND=3306 DB_DATABASE_SECOND=database2 DB_USERNAME_SECOND=root DB_PASSWORD_SECOND=secret In config/database.php ‘mysql’ => [ ‘driver’ => env(‘DB_CONNECTION’), ‘host’ => env(‘DB_HOST’), ‘port’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)