Help me, i am trying put some pagination in my page, but keep showing this error Call to undefined method App\Product::link()
my Code
Blade:
@extends('layouts.index')
@section('content')
<!-- TOP Navbar -->
<div class="w-100 shadow d-flex position-relative position-fixed" style="z-index: 2; background-color: white; ">
<div class="d-flex justify-content-center py-3 mr-auto" style="width: 200px">
<img src="/images/logo.svg" alt="logo icon">
</div>
<div class="pt-4 bd-highlight"><a href="/">
<a href="/create">
<button type="button" class="btn font p-auto rounded-pill text-white font-weight-bold "
style="background-color: #28AD47; width: 178px; height: 40px">New Product
</button>
</a>
</a>
</div>
<div class=" bd-highlight">
<div class="dropdown px-5" style="padding-top: 24px">
<a class=" align-middle font dropdown-toggle" href="#" role="button" id="dropdownMenuLink"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"
style="color: #2c3539">
</a>
<div class="dropdown-menu mt-4" aria-labelledby="dropdownMenuLink" x-placement="bottom-start"
style="position: absolute; transform: translate3d(-20px, 38px, 0px); top: 0px; left: 0px; will-change: transform;">
<a class="dropdown-item" href=""><i class="fa fa-btn fa-user"></i>Profile</a>
<a class="dropdown-item" href=""
onclick="event.preventDefault(); document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="" method="POST" style="display: none;">
</form>
</div>
</div>
</div>
</div>
<!-------------------------->
<div style="background-color: #F8F8F8; z-index: 0;" class="d-flex justify-content-start ">
<div style="width: 200px; height: calc(100vh - 70px);margin-top: 73px;z-index: 1"
class="bg-white shadow position-fixed ">
<div class="d-flex justify-content-center">
<a href="/create">
<p class="font my-5" style="color: #525252"><img src="/images/plus.svg" class="mr-3" alt="plus icon"
width="16px" height="16px">
New Product
</p>
</a>
</div>
<div class="d-flex justify-content-center">
<p class="font my-5" style="color: #525252"><img src="/images/edit.svg" class="mr-3" alt="edit icon"
width="16px" height="16px">
Edit Product
</p>
</div>
</div>
<div class="w-100 " style="margin-top: 73px;margin-left: 200px">
<div class="d-flex justify-content-center">
<h1 class="font p-5">All products</h1>
</div>
<!-- <div style="height: calc(100vh - 202px);background-color: #676767">-->
<div class=" d-flex justify-content-center flex-wrap">
@foreach($products as $product)
<div class="product shadow m-4">
<div class="d-flex justify-content-center mt-3">
<img src="/images/car-example.png" alt="car photo" width="190px" height="140px">
</div>
<div>
<p class="font text-white pt-4 pl-5" style="font-size: 16px">
<img src="/images/info.svg" alt="info icon" width="20px"
height="15px" class="pl-2 mb-1 red-tooltip"
data-toggle="tooltip"
data-placement="right" title=" ">
</p>
</div>
<div class="d-flex bd-highlight" style="margin-top: 40px">
<div class="pl-5 mt-auto bd-highlight">
<h3 class="font text-white">$</h3>
</div>
<div class="bd-highlight ml-auto mt-3 pr-5">
<a href="/">
<button type="button"
class="btn font rounded-pill text-white font-weight-light "
style="font-size: 18px;background-color: #28AD47; width: 99px; height: 41px">
Buy
</button>
</a>
</div>
</div>
</div>
@endforeach
</div>
<div class="w-100" style="background-color: white; z-index: 0;">
<div class=" d-flex justify-content-center pt-2">
</div>
</div>
</div>
</div>
<!-- Bootstrap Link -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
<!-- Hover -->
@endsection
Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request; use App\Product;
class ProductController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index()
{
$products = Product::orderBy('name')->paginate(10);
return view('show')->with('products', $products);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'name' =>'required | unique:product|max:64',
'description' => 'required',
'price' => 'required',
]);
print_r($request->input());
$product = new Product;
$product->name = $request->name;
$product->description = $request->description;
$product->price = $request->price;
echo $product->save();
return redirect('/home');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
web.php:
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('home', 'ProductController');
Route::get('profile', 'UserController@profile')->middleware('auth');
Route::post('profile', 'UserController@update_avatar')->name('profile');
Route::view('create', 'create')->middleware('auth');
Route::post('submit', 'ProductController@store');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire