Method Illuminate\Database\Eloquent\Collection::appends does not exist.
1
Solution:
This error occurs due to the missing sortable function sortable() in the controller.
Step 1:
Open your view (blade) file where you are using sortable to sort the column of the table. Check if the sortable code is correct. For example, if my view file name is product.blade.php It should be like:
product.blade.php
<table>
<thead>
<th>
@sortablelink('id',__('S No'))
</th>
<th>
@sortablelink('name',__('Product Name'))
</th>
<th>
@sortablelink('price',__('Price'))
</th>
</thead>
</table>
Step 2:
Now open your Controller file which is loading your view file, for example, it can be like ProductController.php
Check the function which is loading the view file product.blade.php which can be like function index(). It should use sortable function to fetch data from the database.
ProductController.php
class ProductController extends Controller
{
public function index()
{
$title = "Product Page";
$product=Product::select('products.*')
->orderBy('id','DESC')
->sortable()
->paginate(20);
return view('product.list',compact('title','product'));
}
}
Step 3:
Now open your Model file which should be like Product.php
Its code should have a Sortable line. If its missing add it like below:
Product.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Kyslik\ColumnSortable\Sortable;
class Product extends Model
{
use Sortable;
protected $guarded=[];
public $sortable = ['id','name','price'];
}
Now refresh the browser to see your list of the view page.