for a laravel project, in the dashboard I have several pages (services, products, projects, clients….etc) services it has the cruds of services and projects has the cruds of projects and so on).
In some pages I have this error:
Method IlluminateDatabaseEloquentCollection::appends does not exist. (View: C:laragonwwwnewdashboardresourcesviewsadminservicesindex.blade.php
while this page works correctly despite the fact that they have the same code.
Here is an example of a page that does not work:
ServiceController :
<?php
namespace AppHttpControllersAdmin;
use AppHttpControllersController;
use IlluminateHttpRequest;
use AppModelsService;
use InterventionImageFacadesImage;
class ServiceController extends Controller
{
public function index(Request $request)
{
$filter = $request->get('search_input');
$services = Service::search($filter)->paginate(20);
//$types = Type::get();
//dd($clients);
return view('admin.services.index', compact('services', 'filter'));
}
Models/Service.php :
class Service extends Model
{
use HasFactory;
protected $fillable = [
'name',
'subtitle',
'description',
'image'
];
public function scopeSearch($query, $filter)
{
return $query->where('name', 'like', '%' . $filter . '%');
}
}
in the view I have a table with a foreach and at the bottom:
<div class="card-footer with-pagination">
{{ $services->appends(['filter' => $filter])->links('vendor.pagination.bulma') }}
</div>
and here is the code for a page that works correctly:
PortfolioController.php :
<?php
namespace AppHttpControllersAdmin;
use AppHttpControllersController;
use IlluminateHttpRequest;
use AppModelsPortfolio;
use InterventionImageFacadesImage;
class PortfolioController extends Controller
{
public function index(Request $request)
{
$filter = $request->get('search_input');
$projects = Portfolio::search($filter)->paginate(20);
//$types = Type::get();
//dd($clients);
return view('admin.projects.index', compact('projects', 'filter'));
}
Models/Portfolio.php:
<?php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
class Portfolio extends Model
{
use HasFactory;
protected $fillable = [
'name',
'short_desc',
'desc',
'image',
'cat_id',
'additional',
'faq',
];
public function scopeSearch($query, $filter)
{
return $query->where('name', 'like', '%' . $filter . '%');
}
}
and in the view the same a table with foreach and at the bottom:
<div class="card-footer with-pagination">
{{ $projects->appends(['filter' => $filter])->links('vendor.pagination.bulma') }}
</div>
can anyone help me correct the error? any way, even if I have to change the code completely. or help me find where the error is coming from.
I tried to import classes such as:
use IlluminateDatabaseEloquentCollection;
use IlluminatePaginationPaginator;
and other classes too and I tried in the view links instead of appends:
{{ $technologies->links() }}
but I don’t think that’s the problem. because in the other pages it works without changing anything. it’s too weird.
Yakoub Fergag is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.