My table is like this :
On the mysql, I try like this :
SELECT * FROM players WHERE player_type = 'App\Models\Player'
Data does not showing
So, I add slash like this :
SELECT * FROM players WHERE player_type = 'App\\Models\\Player'
Data showing
Then, In laravel eloquent, I try like this :
$select = array(
'player_type'
);
$query = self::where('player_type', '=', 'App\\\Models\\\Player')
->paginate(10, $select, 'page', null, null);
Data does not showing
How can I solve it?
Just a different approach here, not the solution.
All your models have the same namespace App\\Models\\...
. If so, then just save the actual model in your database without its namespace.
id player_type
1 Player
2 Player
Then later in your controller, you get the palyer type and add the namespace manually when trying to instantiate the Model.
you have to use double quotation ""
not ''
$result = DB::table('users')
->where("city", "App\\Models\\Player")
->get();
dd($result);
I try this in my localhost and it works
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.