Laravel Scout toSql does not exist - laravel

I am trying to get SQL query as a string from query builder. toSql() method works fine without laravel scout. I am using this package for Fulltext search. Here is my code.
Post::toSql(); // Working without scout => select * form post
But I am getting an error when try to search
Post::search('test')->toSql();
Method Laravel\Scout\Builder::toSql does not exist
How Laravel Scout can be extended to add a method toSql to it.

Try this
DB::enableQueryLog();
Post::search('test');
dd(DB::getQueryLog());

Related

How to build Laravel REGEX query including paginate

Following query works fine in phpmyadmin, but I didn`t get figured out, how to put this into Laravel Eloquent with a request:
SELECT * FROM `customers` WHERE company REGEXP '\\MyCompany Corp\\b'
How do I have to create Laravel query if MyCompany Corp is search request like $search->search ??
Thank you for helping out.
use
->where('company', 'regexp', "$search->search")

How to paginate the query results when using Laravel eloquent relationships

I have the following query which retrieves the child configuration records (confch) associated with the parent configuration (confp) and it works fine.
$data["items"] = Confp::find(decrypt($type))->Confch;
I just need to paginate the results.
adding ->paginate(10) would definitly not work as it does not exist in the resulting collection. I found nothing helping in the laravel documentation.
How can I do that please?
Try this instead of above code.
$confp = Confp::find(decrypt($type));
$data["items"] = $confp->setRelation('Confch',$confp->Confch()->paginate(10));

Laravel 5.5 orderby count and paginate

I'm trying to get to order the results by count in laravel 5.5 but haven't found any simple yet working method so far.
What I have tried for example:
$videos = Video::withCount('com_num')->where('active', '1')->orderByDesc('com_num_count')->paginate(51);
But this just gives me:
Call to undefined method Illuminate\Database\Query\Builder::com_num()
Is this possible somehow while using the Laravel's pagination?

How to check eloquent queries in laravel 5?

Im trying to check the eloquent queries to check for n+1 problems.
Im using this "Event::listen('illuminate.query', function($sql){
var_dump($sql);
});" on top of web.php routes file but no query appears. It seems that is because of the version of laravel, that is laravel 5.
Do you know in this version how to properly check the eloquent queries?
Add this to AppServiceProvider::boot() (documentation):
DB::listen(function ($query) {
var_dump($query);
});
try this library dude https://github.com/barryvdh/laravel-debugbar , you will know all of your query

Laravel validation uses eloquent or raw query

I have a question related to laravel validation, My question is when we apply rules like unique or exists, validator query through eloquent model or execute raw query? I am using Laravel 4.2.
I have found answer of my question. According to my investigation Validators run query through Query builder, and by default query builder uses default connection, If you want change the connection, you can through following code.
$verifier = \App::make('validation.presence');
$verifier->setConnection('other_connection_name');
$validation = $this->validator->make($data, static::$rules);
$validation->setPresenceVerifier($verifier);
if($validation->fails()) throw new ValidationException($validation->messages());

Resources