Hi a Laravel beginner here, I have a a manual select query which retrieve the data correctly via DB::select.
Now I want to paginate the result, however manual pagination doesn't work
$pagination = Paginator::make($book, count($book), 5);
and returning the following error
Call to undefined method Illuminate\Pagination\Paginator::make()
I am using Laravel 4.2
Please help
Thanks
You are using the wrong Paginator class. You should change your import to:
use Illuminate\Support\Facades\Paginator;
Or remove the use statement completely since there's an alias registered for just Paginator
Related
My Laravel code is something like this...
Cheque::distinct()->get(['cheque_no'])->paginate('25');
If possible I want to add sortByDesc('updated_at') also.
Please help me.
First off, I think you want
distinct('cheque_no')->get()
instead of
distinct()->get(['cheque_no'])
Then, either you use get or paginate
And you define the sorting at the end
So, the altogether ends up like this:
Cheque::distinct('cheque_no')->paginate(25)->sortByDesc('updated_at');
Sorry for broken english.
I've codeigniter query like this :
$this->db->select('tbl_news.id','tbl_news.news_title','tbl_news.news_desc','tbl_news.date_created','tbl_source.source as source','tbl_news.thumb','tbl_category.category');
$this->db->from('tbl_news');
$this->db->join('tbl_category','tbl_category.id','=','tbl_news.news_category')
$this->db->join('tbl_source','tbl_source.id','=','tbl_news.source')
$data = $this->db->get('', $size, $page)->result_array();
and i try to turn that query to my laravel using query builder, like this :
$data= DB::table('tbl_news')
->select('tbl_news.id','tbl_news.news_title','tbl_news.news_desc','tbl_news.date_created','tbl_source.source as source','tbl_news.thumb','tbl_category.category')
->join('tbl_category','tbl_category.id','=','tbl_news.news_category')
->join('tbl_source','tbl_source.id','=','tbl_news.source')
->get('',$size,$page)
->toArray();
is it posible in laravel to have 'get' with parameter ? because i want to make pagination, but i dont want to use paginate because it will affect the response that i used in my android.
->get('',$size,$page)
Referring to the API documentation for the query builder indicates that the get() method does not support these arguments.
Instead, you should either use the paginate() method or manually paginate the response.
I'm on zend framework 2.
The scenario is, I want to know the actual SQL query after Zend\Db\Sql\Select. I cannot use Zend\Db\Sql\SQL here, and
$select = new Zend\Db\Sql\Select();
$select->where(array($between));
$select->prepareStatement($select)->getSQL();
is giving error like,
Call to a member function getParameterContainer() on null
What is the correct way to write it?
You need to use getSqlString() method.
More info you can find here: https://akrabat.com/displaying-the-generated-sql-from-a-zenddbsql-object/
I'm using Kohana and I'm trying to delete some data in my database. So, I made a request like this :
$env_sol = ORM::factory('EnvironnementSol')
->where('sol_id','=',$id)
->and_where('environnement_id','=', $id_environnement->id)
->find_all();
$env_sol->delete();
And I run the page, it tells me :
Call to undefined method Database_MySQLi_Result::delete()
Can someone tell me why please ?
Instead of using ORM class you can use DB class for that purpose.
DB::delete('EnvironnementSol')
->where('sol_id','=',$id)
->and_where('environnement_id','=', $id_environnement->id)
->execute();
The object pointed to by $env_sol is of type Database_MySQLi_Result which does not have a delete() method.
I am trying to pass data from my controller to my view, but am getting an undefined variable error. usersID is a column in my MySQL table.
Here is the code in my controller
$arrayWithCount = DB :: table("users_has_activities")
-> where("usersID", "=", 19)
-> pluck("usersID");
$countNumber = sizeof($arrayWithCount);
return view('pages.progress', ['countNumber' => $countNumber]);
I have also tried the following return statement without any success
return view::make('pages.progress') -> with('countNumber', $countNumber);
I have also tried reversing the puck and where clauses without any success, I didn't have high hopes that reversing them would fix the problem but thought I would try it any way. Below is the relevant code in the blade file.
<?php echo $countNumber; ?>
This is the error I am currently getting
Undefined variable: countNumber
You code looks fine, if dd() doesn't stop execution of the controller, then another controller is executing. So double check your routes and controllers.
First sizeof should be sizeOf, and is simply an alias for count(). Most people would prefer count over sizeOf as sizeOf (in many languages) would indicate something related to size on disk.
Anywho, being that pluck returns a collection, you have access to count() directly from the collection.
You can probably simply do something like:
$countNumber = $arrayWithCount->count();
Sidenote: Unless there is a particular reason why you are using <?php ?>, in blade, it would be preferred to use {{ and }}.
I had all the controller code in a method I wasn't calling, so the variable was never passed to the blade file. The method was set up to be called on a button press, after fixing that everything works. Thanks Alexey for the help.