skip to Main Content

i want to learn laravel 10 i try to create edit in laravel 10 but i have this error Undefined variable $product. I don’t know how resolve this, i have checked few topics but i don’t understant how resolve this. Someone can help me how can i do for i can edit title and detail, and leave this error. Because few hours i check in google and youtube but i dont understand how can i do this.

welcome

  <body class="scrollspy-example" data-bs-spy="scroll" data-bs-target="#navbar" data-bs-offset="0" tabindex="0">
    <nav class="navbar navbar-expand-lg navbar-light py-4 py-lg-0 fixed-top bg-white border-bottom">
      <div class="container"><a class="navbar-brand font-serif text-uppercase h6 text-primary fw-bold mb-0" href="#intro">It Worker</a>
        <button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
            <li class="nav-item"><a class="nav-link text-uppercase active" href="#intro">Главная</a></li>
            <li class="nav-item"><a class="nav-link text-uppercase" href="#about">О бюро</a></li>
            <li class="nav-item"><a class="nav-link text-uppercase" href="#services">Что мы можем предложить</a></li>
            <li class="nav-item"><a class="nav-link text-uppercase" href="#contact">Контакт</a></li>
          </ul>
        </div>
      </div>
    </nav>
    <!-- INTRO SECTION-->
    <section class="intro bg-cover bg-center d-flex align-items-center dark-overlay" id="intro" style="background: url(img/home.jpg)">
      <div class="overlay-content text-white w-100">
        <div class="container text-center">
          <div class="row">
            <div class="col-lg-11 mx-auto">
              <!-- <div class="pb-5 mb-lg-5 wow fadeInDown"><img src="img/logo-big.png" alt="..." width="130"></div> -->
              <h1 class="intro-heading mb-5 wow fadeInDown" data-wow-delay="0.3s">{{ $product->title }}</h1>
              <p class="h3 intro-text fw-normal wow fadeInUp" data-wow-delay="0.6s">{{ $product->detail }}</p>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!--  /- END INTRO SECTION-->
    <!-- ABOUT SECTION -->
    <section id="about">
      <div class="container">
        <header class="mb-5 text-center">
          <h2 class="heading wow fadeInUp" data-wow-delay="0.3s">О бюро</h2>
        </header>
        <div class="row gy-4">
          <div class="col-lg-12 wow fadeInUp" data-wow-delay="0.3s">
            <p> An sincerity so extremity he additions. Her yet <strong>there truth merit</strong>. Mrs all projecting favourable now unpleasing. Son law garden chatty temper. Oh children provided to mr elegance marriage strongly. Off can admiration prosperous now devonshire diminution law.</p>
            <p> Received overcame oh sensible so at an. Formed do change merely to county it. <strong>Am separate contempt</strong> domestic to to oh. On relation my so addition branched. Put hearing cottage she norland letters equally prepare too. Replied exposed savings he no viewing as up. Soon body add him hill. No father living really people estate if. Mistake do produce beloved demesne if am pursuit.</p>
            <p> An sincerity so extremity he additions. Her yet <strong>there truth merit</strong>. Mrs all projecting favourable now unpleasing. Son law garden chatty temper. Oh children provided to mr elegance marriage strongly. Off can admiration prosperous now devonshire diminution law.</p>
          </div>
        </div>
      </div>
    </section>
    <!-- /- END ABOUT SECTION -->
    <!-- SERVICES SECTION -->
    <section class="bg-primary text-white" id="services">
      <div class="container text-center">
        <header class="mb-5 wow fadeInDown">
          <h2 class="heading heading-white">Что мы можем предложить</h2>
        </header>
        <div class="row gy-3">
          <div class="col-lg-4 wow fadeInUp" data-wow-delay="0s"><i class="fa-4x fa-fw icon-shadow-primary mb-3 fas fa-search"></i>
            <h3 class="fw-normal mb-3">Consulting</h3>
            <p class="text-start small">On on produce colonel pointed. Just four sold need over how any. In to september suspicion determine he prevailed admitting. On adapted an as affixed limited on. Giving cousin warmly things no spring mr be abroad. Relation breeding be as repeated strictly followed margaret. One gravity son brought shyness waiting regular led ham.</p>
          </div>
          <div class="col-lg-4 wow fadeInUp" data-wow-delay="0.2s"><i class="fa-4x fa-fw icon-shadow-primary mb-3 fab fa-html5"></i>
            <h3 class="fw-normal mb-3">HTML coding</h3>
            <p class="text-start small">Manor we shall merit by chief wound no or would. Oh towards between subject passage sending mention or it. Sight happy do burst fruit to woody begin at. Assurance perpetual he in oh determine as.</p>
          </div>
          <div class="col-lg-4 wow fadeInUp" data-wow-delay="0.4s"><i class="fa-4x fa-fw icon-shadow-primary mb-3 fas fa-tachometer-alt"></i>
            <h3 class="fw-normal mb-3">PHP webdelopment</h3>
            <p class="text-start small">Rooms oh fully taken by worse do. Points afraid but may end law lasted. Was out laughter raptures returned outweigh. Luckily cheered colonel me do we attacks on highest enabled. Tried law yet style child. Bore of true of no be deal.</p>
          </div>
        </div>
        <hr class="my-4">
        <div class="wow fadeInUp" data-wow-delay="0.6s">
          <p class="lead">Would you like to know more or just discuss something?</p><a class="btn btn-outline-light" href="#contact">Contact me </a>
        </div>
      </div>
    </section>
    <!-- /- END SERVICES SECTION -->

    <!-- STATISTICS SECTION -->
    <section class="text-white dark-overlay" id="statistics">
      <div class="parallax" data-parallax-image="img/parallax.jpg"></div>
      <div class="overlay-content py-5">
        <div class="container">
          <div class="row text-center">
            <div class="col-lg-3 col-mg-6 wow fadeInUp" data-wow-delay="0s">
              <div class="icon mb-3 mx-auto"><i class="fas fa-bars"></i></div>
              <p class="text-lg mb-0 fw-light" id="counter1">0</p>
              <p class="lead fw-normal lh-1 text-uppercase">Websites</p>
            </div>
            <div class="col-lg-3 col-mg-6 wow fadeInUp" data-wow-delay="0.2s">
              <div class="icon mb-3 mx-auto"><i class="fas fa-users"></i></div>
              <p class="text-lg mb-0 fw-light" id="counter2">0</p>
              <p class="lead fw-normal lh-1 text-uppercase">Satisfied Clients</p>
            </div>
            <div class="col-lg-3 col-mg-6 wow fadeInUp" data-wow-delay="0.4s">
              <div class="icon mb-3 mx-auto"><i class="fas fa-copy"></i></div>
              <p class="text-lg mb-0 fw-light" id="counter3">0</p>
              <p class="lead fw-normal lh-1 text-uppercase">projects</p>
            </div>
            <div class="col-lg-3 col-mg-6 wow fadeInUp" data-wow-delay="0.6000000000000001s">
              <div class="icon mb-3 mx-auto"><i class="fas fa-font"></i></div>
              <p class="text-lg mb-0 fw-light" id="counter4">0</p>
              <p class="lead fw-normal lh-1 text-uppercase">Magazines and brochures</p>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!-- /- END STATISTICS SECTION -->
    <!-- REFERENCES SECTION -->
   
       <!-- CONTACT SECTION -->
    <section id="contact">
      <div class="container wow bounceIn">
        <header class="text-center mb-5">
          <h2 class="heading">Контакт</h2>
        </header>
        <div class="row">
          <div class="col-lg-7 mx-auto">
            <form>
              <div class="row gy-3">
                <div class="col-lg-6">
                  <input class="form-control" type="text" name="firstname" placeholder="Имя *" required>
                </div>
                <div class="col-lg-6">
                  <input class="form-control" type="text" name="lastname" placeholder="Фамилия *" required>
                </div>
                <div class="col-lg-12">
                  <textarea class="form-control" name="message" rows="7" placeholder="Сообщение *"> </textarea>
                </div>
                <div class="col-12 text-center">
                  <button class="btn btn-outline-primary" type="submit">Послать</button>
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>
    </section>
    <!-- /- END CONTACT SECTION -->
    <!-- MAP SECTION-->
    <div id="map"><iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d73756.42398370031!2d20.39431908415674!3d54.71158921481271!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x46e33d8d4b7c21a9%3A0x5050960016126ed3!2sKaliningrad%2C%20Kaliningrad%20Oblast!5e0!3m2!1sen!2sru!4v1679741278758!5m2!1sen!2sru" width="100%" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe></div>
    <!-- /- END MAP SECTION -->
    <footer class="py-5 bg-dark text-light">
      <div class="container py-3">
        <div class="row gy-3 mb-4 text-center align-items-center">
          <div class="col-md-6 text-lg-start">
            <ul class="list-inline">
              <li class="list-inline-item"><a class="social-link facebook" href="#!"> <i class="fab fa-facebook-f"></i></a></li>
              <li class="list-inline-item"><a class="social-link instagram" href="#!"> <i class="fab fa-instagram"></i></a></li>
              <li class="list-inline-item"><a class="social-link pinterest" href="#!"> <i class="fab fa-pinterest"></i></a></li>
              <li class="list-inline-item"><a class="social-link email" href="#!"> <i class="fas fa-envelope"></i></a></li>
            </ul>
          </div>
          <div class="col-md-6 text-lg-end">
            <p class="mb-0 font-serif text-sm">© 2022 Your name goes here. All rights reserved.</p>
          </div>
        </div>
        <div class="text-center">
          <p class="mb-0 small">Template designed by <a href="https://bootstrapious.com">Bootstrapious</a>. </p>
        </div>
      </div>
    </footer>
    <!-- JavaScript files-->
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="vendor/swiper/swiper-bundle.min.js"></script>
    <script src="vendor/waypoints/lib/noframework.waypoints.min.js"></script>
    <script src="vendor/universal-parallax/universal-parallax.min.js"></script>
    <script src="vendor/wow.js/wow.min.js"></script>
    <script src="vendor/leaflet/leaflet.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/countup.js/1.8.2/countUp.min.js"></script>
    <script src="vendor/mixitup/mixitup.js"></script>
    <script src="js/leaflet.js"></script>
    <script src="js/theme.js"></script>
    <!-- FontAwesome CSS - loading as last, so it doesn't block rendering-->
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
  </body>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>

</html>

views/admin/price/edit.blade.php

@extends('admin.layout.layout')
  @section('content')
  <section class="content">
      <div class="container-fluid">
        <div class="row justify-content-center">
          <!-- left column -->
          <div class="col-md-6">
              <div class="card-header">
                <h3 class="card-title">Цены</h3>
              </div>
              <!-- /.card-header -->
  <!-- Content Wrapper. Contains page content -->
  
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-8">
            <h1>Сменить первую партию</h1>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            <table class="table">
              <thead>
                <tr>
                  <th>Titre</th>
                  <th>Description</th>
                  <th>Modifier</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>Hello, hola</td>
                  <td>I grind HTML and CSS and then weld them with PHP into beautiful and efficient websites.</td>
                  <td><a href="{{ url('admin/price/edit') }}" type="button" class="btn btn-primary">Modifier</a></td> 
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </section>
    <!-- /.content -->

  <!-- /.content-wrapper -->
                <!-- /.card-body -->              
            <!-- /.card -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  @endsection

ProductController

<?php

namespace AppHttpControllers;

use AppModelsProduct;
use IlluminateHttpRequest;

class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        return view('admin.price.edit');
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     */
    public function show(Product $product)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(Product $product)
    {
        return view('admin.price.edit');
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, Product $product)
    {
        $request->validate([
            'title' => 'required',
            'detail' => 'required',
        ]);     

        $product->update($request->all());

        return redirect()->route('products.index')
                        ->with('success','Product updated successfully');
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(Product $product)
    {
        //
    }
}

web

<?php

use IlluminateSupportFacadesRoute;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/price', function () {
    return view('price');
});

Route::get('/admin/price/price', function () {
    return view('/admin/price/price');
});

Route::get('/admin/price/vtoraya', function () {
    return view('/admin/price/vtoraya');
});

Route::get('/admin/price/tretya', function () {
    return view('/admin/price/tretya');
});

Route::get('/admin/price/chetvertaya', function () {
    return view('/admin/price/chetvertaya');
});

Route::get('/admin/price/edit', [AppHttpControllersProductController::class, 'edit']);


Route::prefix('/admin')->namespace('AppHttpControllersAdmin')->group(function(){
    Route::match(['get','post'],'login','AdminController@login');

    Route::group(['middleware'=>['admin']],function(){
        Route::get('dashboard', 'AdminController@dashboard');
        Route::match(['get','post'],'update-password', 'AdminController@updatePassword');
        Route::post('check-current-password','AdminController@checkCurrentPassword');
        Route::get('logout', 'AdminController@logout');
    });
});

2

Answers


  1. You need to pass $product to your controller.

        public function edit(Product $product)
        {
            return view('admin.price.edit', ['product' => $product]));
            // or: return view('admin.price.edit')->with('product', $product);
        }
    
    Login or Signup to reply.
  2. Your route needs to pass something to your controller for example your route would look something like:

    Route::get('/products/edit/{product}',[Product::class,'edit']);
    

    Note that {product} is the product id, you will get it from your url as an example :

    <a href="{{route("products.show",$product->id)}}" class="ml-1 underline">{{$product->name}}</a>

    Then in your controller

    public function edit(Product $product)
    {
        return view('admin.price.edit',compact($product));
    }
    

    Check Laravel docs for more information

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search