Laravel add custom attribute to paginate result

I’m trying to add some data into the paginate result. This is the code: // query select and filter […] $totalAmount = $sales->sum(‘amount’); $result = $sales->paginate($rowsPerPage); return $result; The result is: { “datatable”: { “current_page”: 1, “data”: [ { “sale”: 13047689, “customer”: “0017850000104”, “date”: “2015-12-23 23:15:06”, “amount”: “129.84”, } ], “first_page_url”: “http://intranet/api/user/sales/datatable?custom=value&page=1”, “from”: 1, “last_page”:…

Laravel, use pagination Method Illuminate\Database\Eloquent\Collection::render does not exist

I’m trying to use paginate but it doesn’t work, without paginate all are fine but when I use it I get this error Method Illuminate\Database\Eloquent\Collection::links does not exist Controller: $userorders=Userorder::where(‘user_id’,$user_id)->with(‘storeinfo’)->with(‘product’)->paginate(15)->groupBy(‘order_number’); view: @if(count($userorders)>0) {!! $userorders->links() !!} @endif

PHP/Laravel Check a condition in a function only once

I have written a custom translation function for Laravel, which first checks a configuration variable to see whether to use Laravel’s default __() function or my custom trans() function. Here’s my function: function t($key, $replace = [], $locale = null) { $source = Config::get(‘translate.source’); if ($source == ‘database’) { return trans($key, $replace, $locale); } else…

Laravel subdomain .htaccess // error 500 (Wedos)

I’ve tried every solution here. My problem is my shared webhosting provider has blocked MultiViews. My main domain build with laravel works ( liated.cz ) but my subdomain keeps giving me errors 500 / 403 or infinite loop, it depends which .htaccess i write Structure: www —–domains ————–liated.cz // Works ————–testing.liated.cz // Errors —–subdomains In…

How to delete file after 1 week from folder and database in laravel 6?

Currently I store the files in the public folder in a file called “files”. I want it to automatically delete the file after 1 week and it to delete it from the database. FileController.php public function store(Request $request) { $file = $request->file(‘file’); $new_name = rand() . ‘.’ . $file->getClientOriginalExtension(); $file->move(public_path(“files”), $new_name); $upload = new File();…