I’m beginner on Laravel… How to debug some value on controller in Laravel, result can show to console like syntax console.log() on javascript? example controller function : Answer In Laravel use dd($id) or if you don’t want to halt the execution, you can use dump($var). You can still always use PHP’s native functions like var_dump, die and print_r.
Tag: laravel
Xdebug laravel artisan commands
I regularly use xdebug to debug applications, I’ve built a laravel application that takes an upload of a csv inserts the data to the database and the ids to a job queue. I’ve written an artisan …
Which to use Auth::check() or Auth::user() – Laravel 5.1?
If I want to check whether the user is logged in within my Laravel 5.1 application I can either use or is there a reason to prefer one over the other when checking if a user is logged in? Answer Auth::check() defers to Auth::user(). It’s been that way since as long as I can remember. In other words, Auth::check() calls
Laravel findOrFail with related data?
In my Menu controller I have a method which should display the specified record and all its children. I have two models: MenuItem and MenuVariation, My items will have many variations as outlined in …
Laravel 5.1 – Checking a Database Connection
I am trying to check if a database is connected in Laravel. I’ve looked around the documentation and can’t find anything. The closest thing I’ve found is this, but this doesn’t solve my problem. I have three instances of MySQL that are set up on different machines. Below is a simplified version of what I am trying to achieve. If
Laravel 5.1 xmlHttpRequest AJAX POST TokenMismatchException
The relevant code is shown below: I’ve been trying to figure this out for hours now, I honestly have no idea what to do at this point. Note, that if I use the form method everything works just fine. I’ve also tried sending the CSRF token as a parameter in the postString: “_token=” + csrfToken Answer The problem was resolved
How to get client IP address in Laravel 5+
I am trying to get the client’s IP address in Laravel. It is easy to get a client’s IP in PHP by using $_SERVER[“REMOTE_ADDR”]. It is working fine in core PHP, but when I use the same thing in …
Laravel `array_pluck` on any key
Is possible use something like array_pluck($array, ‘users.*.id’)? Imagine that I have: And I want get [1, 2, 3]. I tried something like: users.*.id, users.id and users..id, but nothing worked. Answer From Laravel 5.7, you may use the Arr::pluck() helper. Use array_pluck($array[‘users’], ‘id’) The function only supports a single dimensional array. It will search for keys in the array which match
Laravel 5 Send Errors to Email
I am trying to figure out how I can send errors to my email in Laravel 5. I haven’t had much luck finding any good resources. There used to be good packages like: https://github.com/TheMonkeys/laravel-error-emailer That did this for you in Laravel 4. They have yet to release a Laravel5 update because of the way they changed error handling… which I
Laravel – Form validation error – argument 2 must be array
I’m working with Laravel and every time I submit my form it gives me this error: ErrorException in Factory.php line 91: Argument 2 passed to IlluminateValidationFactory::make() must be of the type array, null given, called in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/FormRequest.php on line 83 and defined This is some code for the controller, even when I don’t try to send data to the database