Sunpower
130
10
Laravel

How to convert controller things to blade view in laravel

Posted 4 months ago by Sunpower

in my laravel app I have following controller function

public function filterbrand ()
    {
        $vehicles = DB::table('vehicles')
                    ->orderBy('categoryname', 'asc')
                    ->get();


    $cat = "";
    foreach($vehicles AS $vehicle) {
        if($vehicle->categoryname != $cat) {
            $cat = $vehicle->categoryname;
            echo $cat . '<br><br>';
        }

        echo $vehicle->brandname . '<br>';
    }
    
    }

now I need change it as following

public function filterbrand ()
    {
        $vehicles = DB::table('vehicles')
                    ->orderBy('categoryname', 'asc')
                    ->get();
return view('vehicles.brand')->withVehicles($vehicles);

and paste this codes in brand blade file

   $cat = "";
    foreach($vehicles AS $vehicle) {
        if($vehicle->categoryname != $cat) {
            $cat = $vehicle->categoryname;
            echo $cat . '<br><br>';
        }

        echo $vehicle->brandname . '<br>';
    }

how can I make above blade view codes in blade file?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.