Undefined method IlluminateDatabaseQueryBuilder::setPath()

Multi tool use
Multi tool use


Undefined method IlluminateDatabaseQueryBuilder::setPath()



I am trying to call my table called "Carousel". But it's getting an error.
I already created for my Model. I am using php myadmin.



Error Message :



undefined method IlluminateDatabaseQueryBuilder::setPath()



Carousel model


<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class Carousel extends Model
{

}



Controller


function getsearchCarousel(Request $req){

if($req->has('searchcar')){
$data = Carousel::where('carouselName','like',$req->input('searchcar').'%')->select('id','carouselName, carouselPhoto');
$data->setPath($req->url()."?searchcarousel=".$req->searchcar);
return view('Admin.Page.Carousel.carousel')->with('data', $data);
}
else{
return redirect('/Admin/Page/carousel');
}
}





Where is that "setPath" method defined?
– Amarnasan
Jul 3 at 6:07




2 Answers
2



You are missing the ->get() part


->get()


$data = Carousel::where('carouselName','like',$req->input('searchcar').'%')->select('id','carouselName, carouselPhoto')->get();



So, provided there is a setPath function defined in your model, now you'll find it, because actually you are trying to get it from the queryBuilder.





But ->get() return instance of IlluminateDatabaseEloquentCollection not Corusel model ???
– Davit
Jul 3 at 6:43




In your code you dont get data in db. For get data in db you must be use after your code ->get() or ->first() method.


->get()


->first()


$carusels = Carousel::where('carouselName','like',$req->input('searchcar').'%')
->select('id','carouselName, carouselPhoto')
->get();



This case carusels is instance of IlluminateDatabaseEloquentCollection and you you must be use forecah to get separate $carusel


carusels


IlluminateDatabaseEloquentCollection


foreach($carusels as $data) {
$data->setPath($req->url()."?searchcarousel=".$req->searchcar);
}



and in your Courusel model define setPath method.


Courusel


setPath



Also you can get single data using ->first


->first


$carusels = Carousel::where('carouselName','like',$req->input('searchcar').'%')
->select('id','carouselName, carouselPhoto')
->first();
$data->setPath($req->url()."?searchcarousel=".$req->searchcar);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

SZVtPojKGOrn66Yv
XgRxe PUsx07ZcCPPSB,SlabZN5UTXNIGZ A7GqHUAJK1SEfU6div9F0JhqUx,8,ewv NJj1,GKfGJRhFkF

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications