I am trying to make an edit page like in this video: https://www.youtube.com/watch?v=PAP8IS_ak6w But i am trying use and not , but is not working, but my create page is working normal and is basically the same.
Is showing error 404|NOT FOUND
Here is my code:
edit.blade.php:
@extends('layouts.index')
@section('content')
<div class="head">
<div class="m-auto center" style="width: 480px;">
@if ($errors->any())
@foreach ($errors->all() as $error)
<div style="height: 550px; border-radius: 35px; background-color: #F0EFEF">
<div class="d-flex justify-content-center ">
<h4 class="font py-5" style="color: #7B7B7B; ">Edit a new Product</h4>
</div>
<div class="d-flx justify-content-center">
<div style="margin-left: 60px">
<p class="font text-weight-light text-danger"> </p></div>
<form action="submit" method="post">
<div class="d-flex justify-content-center ">
<input class="w-75 shadow py-2 font pl-2" type="text" name="name" maxlength="64"
placeholder="Product Name"
style="border:none; border-radius: 4px" required></div>
<div class="d-flex mt-4 justify-content-center">
<textarea class=" w-75 pt-2 shadow font pl-2" type="text" name="description"
placeholder="Description"
style="border:none; border-radius: 4px; height: 100px; resize: none"
required></textarea>
</div>
<div class="row mt-4 ">
<select class="form-control border-0 shadow mt-2" id="exampleFormControlSelect1"
style="width: 150px; margin-left: 75px"
name="category">
<option>Classic</option>
<option>Sports car</option>
<option>Luxury vehicle</option>
<option>Van</option>
<option>Truck</option>
</select>
<div style="margin-left: 37px">
<p class="font m-3" style="color: #7B7B7B;">Price</p></div>
<input class="shadow font p-1 text-center mt-2" type="number" min="0.01" step="0.01"
max="2500.00" placeholder="0.00" name="price"
style="border:none; border-radius: 4px; width: 100px; height: 40px;"
required></div>
<div class="d-flex justify-content-center mt-5">
<div class=" m-3">
<a href="/your"><p style="color: dimgray; "><strong>GO BACK</strong></p></a>
</div>
<div class="mt-2 ml-5">
<button type="submit"
class="btn font rounded-pill text-white font-weight-bold "
style="background-color: #28AD47; width: 178px">Save
</button>
</div>
</div>
</form>
</div>
</div>
</div>
@endforeach
@else
<div style="height: 550px; border-radius: 35px; background-color: #F0EFEF">
<div class="d-flex justify-content-center ">
<h4 class="font py-5" style="color: #7B7B7B">Edit a new Product</h4>
</div>
<form action="submit" method="post">
<div class="d-flex justify-content-center ">
<input class="w-75 shadow py-2 font pl-2" type="text" name="name" maxlength="64"
placeholder="Product Name"
style="border:none; border-radius: 4px" required></div>
<div class="d-flex mt-4 justify-content-center">
<textarea class=" w-75 pt-2 shadow font pl-2" type="text" name="description"
placeholder="Description"
style="border:none; border-radius: 4px; height: 100px; resize: none"
required></textarea>
</div>
<div class="row mt-4 ">
<select class="form-control border-0 shadow mt-2" id="exampleFormControlSelect1"
style="width: 150px; margin-left: 75px"
name="category">
<option>Classic</option>
<option>Sports car</option>
<option>Luxury vehicle</option>
<option>Van</option>
<option>Truck</option>
</select>
<div style="margin-left: 37px">
<p class="font m-3" style="color: #7B7B7B;">Price</p></div>
<input class="shadow font p-1 text-center mt-2" type="number" min="0.01" step="0.01"
max="2500.00" placeholder="0.00" name="price"
style="border:none; border-radius: 4px; width: 100px; height: 40px;"
required></div>
<div class="d-flex justify-content-center " style="margin-top: 70px">
<div class=" m-3">
<a href="/your"><p style="color: dimgray; "><strong>GO BACK</strong></p></a>
</div>
<div class="mt-2 ml-5">
<button type="submit" name="submit"
class="btn font rounded-pill text-white font-weight-bold "
style="background-color: #28AD47; width: 178px">Save
</button>
</div>
</div>
</form>
</div>
</div>
@endif
@endsection
ProductController.php:
<?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',
'category' => 'required',
'price' => 'required',
]);
print_r($request->input());
$product = new Product;
$product->name = $request->name;
$product->description = $request->description;
$product->category = $request->category;
$product->price = $request->price;
$product->user_id = auth()->user()->id;
echo $product->save();
return redirect('/home');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$product = Product::find($id);
return view('your')->with('product', $product);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$product = Product::find($id);
return view('edit')->with('product', $product);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request, [
'name' =>'required | unique:product|max:64',
'description' => 'required',
'category' => 'required',
'price' => 'required',
]);
print_r($request->input());
$product = Post::find($id);
$product->name = $request->input('name');
$product->description = $request->input('description');
$product->category = $request->input('category');
$product->price = $request->input('price');
echo $product->save();
return redirect('/your');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
web.php:
<?php
use Illuminate\Support\Facades\Route;
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');
Route::post('submit', 'ProductController@update');
Route::get('/your', 'YourController@index');
How can I avoid the error?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire