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 :
class TestMeController extends Controller {
public function __construct()
{
$this->middleware('jsonify');
}
public function callMe($id)
{
$params = Request::all();
console.log($id); <== how to write code on Laravel?
}
}
You can use print_r ($request->all ()) method to print the form data in laravel. It will print all the submitted form input attributes and values in your controller file.
So, if you want to use dump () to print the data, you can use die () to halt the process. Otherwise, dd () can do the same. var_dump () and print_r () will show the messy array of Laravel collection to solve this you can also convert Laravel collection into array and print with dd (), dump () or var_dump () and print_r ().
var_dump () and print_r () will show the messy array of Laravel collection to solve this you can also convert Laravel collection into array and print with dd (), dump () or var_dump () and print_r (). I prefer to use <pre> tag surround the php’s native function print_r () to prettify the array data.
Controllers can group related request handling logic into a single class. For example, a UserController class might handle all incoming requests related to users, including showing, creating, updating, and deleting users. By default, controllers are stored in the app/Http/Controllers directory. Let's take a look at an example of a basic controller.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With