jeudi 4 juillet 2019

I want to make custom php class for custom helpers function ... is it possible in laravel?

I am working on the E-Commerce Application that builds on the laravel platform... I want to check a stock of every product when I was fetching if stock not available so that will show stock isn't available on product card else show add-to-cart button. The Problem is Product cards available on different pages how can I do this ? can I make helper class function or ... please guide

this is my helper class code,

   use App\ProductsAttribute;
   function hello($id)
   {
       return "hello : ".$id;
   }
   function getStock($id)
   {
   $c = ProductsAttribute::where('id',$id)->select('stock')->get();
   $count_stock = json_decode(json_encode($c));
   $res = $count_stock;
   return $res;
   }

or this is my IndexController code :

    public function index(Request $request){

       // $productsAll = Product::paginate(12);
       $productsAll = Product::orderByRaw('RAND()')->take(12)->get();

       $arrProducts = Product::inRandomOrder()->skip(0)->take(15)->get();
       $arrProducts = json_decode(json_encode($arrProducts));



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2YAislW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire