Create controller file ‘app/Http/Controllers/ProductController.php‘ and paste the given code below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?php namespace App\Http\Controllers; use DB; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; class ProductController extends BaseController { public function index(){ $products = DB::table('products') ->selectRaw('*') ->where('status', '=', 1) //->where('id', '=', $id) ->get(); return view("products/productList",compact('products')); } public function detail($id){ $products = DB::table('products') ->selectRaw('*') ->where('status', '=', 1) ->where('id', '=', $id) ->get(); return view("products/productDetail",compact('products')); } } |
public function index() and public function detail($id) are methods you can remove these method and write your own.
in detail($id) method you can see select query with multiple where clause in laravel.