dimanche 4 février 2018

Laravel - How to get data from Messagebag ($errors)

I'm tried to send data with $errors. But I can't use it in my blade. When I said $errors->all() it gives me below eror

Array to string conversion (View: /var/www/laravel/resources/views/frontend/categories.blade.php)

my controller btw

public function orderProducts(Request $request)
{
    if (is_null($request->price)) {
        return back();
    } else {
        $productModal = new Product;
        $product100 = $productModal->whereBetween('price', [0, 100])->get();
        $product200 = $productModal->whereBetween('price', [100, 200])->get();
        $product300 = $productModal->whereBetween('price', [200, 300])->get();
        $product400 = $productModal->whereBetween('price', [300, 400])->get();
        $product500 = $productModal->whereBetween('price', [400, 500])->get();
        $products = collect();

        for ($i=0;$i<count($request->price);$i++){
            if ($request->price[$i]==1) {
                $products = $products->merge($product100);
            }elseif ($request->price[$i]==2) {
                $products = $products->merge($product200);
            }elseif ($request->price[$i]==3) {
                $products = $products->merge($product300);
            }elseif ($request->price[$i]==4) {
                $products =  $products->merge($product400);
            }elseif($request->price[$i]==5) {
                $products = $products->merge($product500);
            }
        }
        return back()->withErrors(compact('products'));
    }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire