samedi 27 janvier 2018

Laravel 5.5 call Controller function from blade view with parameter

I have a slider of products and i'm trying to find the lowest price of each product.

So i'm trying, first of all, to successfully call a function from a Controller and pass the id of the product and also print it out.

blade.php

 <span class="text-bold">
   @php
    use App\Http\Controllers\ServiceProvider;
    echo ServiceProvider::getLowestPrice($product_cat->id);
   @endphp
 </span>

Route

Route::post('/getLowestPrice/{id}', 'ServiceProvider@getLowestPrice');

Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ServiceProvider extends Controller
{
    public static function getLowestPrice($id) {
        return $id;
    }
}

And I get an error

Parse error: syntax error, unexpected 'use' (T_USE) 

Any idea why use is not working here?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire