Category : laravel

Due to application versions, I have 3 laravel Homestead boxes. I’m using MacOS. Laravel Homestead 9.7.2 Laravel Homestead 12.2 Laravel Homestead 12.6 For each of them I do: v10.17 laravel/homestead 9.7.2 Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-124-generic x86_64) $ vagrant ssh then $ mailhog 2021/09/28 23:10:17 Using in-memory storage 2021/09/28 23:10:17 [SMTP] Binding to ..

Read more

I would like you can help me with this issue I have. I have this method in my controller: public function comments(Post $post) { $comments = $post->load(‘user’)->comments()->paginate(10); return (CommentResource::collection($comments))->response(); } This return a response like this: { "data": [ { "id": 43, "content": "fffffffff", "image_path": null, "created_at": "2021-09-28T20:53:43.000000Z", "user": { "id": 1, "name": "Demo", "verified": ..

Read more

how to make the encryption shorter in characters? Crypt::encrypt($event->id)) Result: http://myurl/id/eyJpdiI6Im5ub0hyaWJwVE1iendYbHNaSzJsSXc9PSIsInZhbHVlIjoiVHhpNmF4b3NlQjk2NFluRXhCOFZuQT09IiwibWFjIjoiZDkxNzk2OTlmZGRmZWJjYjFlNjExYjcyNWU4Y2Y4NWYwMjYxMTkxN2ZmNzU3NGM4Nzg0OWJkNjk1NmExNjVkZiIsInRhZyI6IiJ9 generates a very large link, I need to shorten it, is it possible? Sourc..

Read more

$validator = Validator::make($request->all(), [ ’email’ => ‘required|min:9|max:50|email’, ‘password’ => ‘required|min:8|max:255|password’ ]); if ($validator->fails()) { echo "Failed! Sorry :("; Session::flash(‘error’, $validator->messages()->first()); //return Redirect::back()->withErrors($validator); } else {… But if I write ‘password’ => ‘required|min:8|max:255’ the validation is passed, but when I write ‘password’ => ‘required|min:8|max:255|password’ it doesn’t pass and the result is "Failed! Sorry :(". I mean ..

Read more

I installed Laravel Passport and migrated the new tables just fine in my database. But when I try to run migrations for the testing database, ie. artisan migrate –database=testing I get: SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘oauth_auth_codes’ already exists The only table that exists in the testing database is the migrations ..

Read more

** I am using backpack laravel. I created two custom buttons "approve" and "disapprove".** <script src="https://code.jquery.com/jquery-2.2.4.js"></script> <button class="btn btn-xs btn-default" id="a{{$entry->getKey()}}" name="approved"> <i class="fa fa-check"> </i> Approve </button> <script type = ‘text/javascript’> $(document).ready(function(){ $("#a{{$entry->getKey()}}").on("click", function(){ var name = document.getElementById("a{{$entry->getKey()}}").attributes[2].value; var num = document.getElementById("a{{$entry->getKey()}}").attributes[1].value; $.ajax({ url : ‘{{url(‘getMessage/{num1}’)}}’, type:’POST’, data: { "num1": num, _token: ‘{{csrf_token()}}’, "name": ..

Read more

I have this Warehouse → many to many → Product → has many → Sale My relationships warehouse.php public function products () { return $this->belongsToMany(Product::class)->withPivot(‘quantity’); } product.php public function sales () { return $this->hasMany(Sale::class); } I want to get sales for each warehouse What I have tried return Warehouse::with(‘products.sales’)->get(); Unexpected restult { "id": 1, "warehouse": ..

Read more

In my laravel based application, when updating user accounts I’m trying to validate the birthday field. I have the following in my controller’s update method ‘date_of_birth’=>[‘required’,’date’, ‘date_format:Y-m-d’, function ($attribute, $value, $fail) { $age=Carbon::createFromFormat(‘Y-m-d’, $value)->diff(Carbon::now())->y; if($age<18||$age>70){ $fail(‘Âge invalide. l’âge devrait être 18-70’); } },] So the date format has to be Y-m-d and the age range ..

Read more

I have implemented this relationship where a warehouse belongsToMany products that has Many sales. My models be like warehouse.php public function products () { return $this->belongsToMany(Product::class)->withPivot(‘quantity’); } product.php public function sales () { return $this->hasMany(Sale::class); } I want to access sales directly from my Warehouse model to sum a column in the sales table. I ..

Read more

Route::get("test", function (){ $result = IlluminateSupportFacadesSession::get("filter_values"); IlluminateSupportFacadesSession::forget("filter_values"); IlluminateSupportFacadesSession::put(‘filter_values’, "abcdef"); dd("result: ", $result); }); Why the session return null when the page is refreshed ? Sourc..

Read more

Inside a controller in Laravel I have this: public function index() { $users = User::orderBy(‘name’, ‘asc’)->paginate(13); $users2 = User::all(); return view(‘contatos.index’)->with(‘users’, $users); return view(‘auth.register’)->with(‘users’, $users2); } I know isn’t right, it’s just to demonstrate my logic. Is there a way to unite these two returns in a single return? Or even a much shorter form ..

Read more