Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print out value on controller Laravel?

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?
    }
}
like image 225
monoy suronoy Avatar asked Nov 09 '15 06:11

monoy suronoy


People also ask

How to print form data in 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.

How to print a messy array of Laravel data?

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 ().

How to convert Laravel collection to array and print in PHP?

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.

What are controllers in Laravel?

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.


1 Answers

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.

like image 186
Dexter Bengil Avatar answered Oct 12 '22 23:10

Dexter Bengil