programmer111

programmer111

Member Since 2 Months Ago

Experience Points 1,040
Experience Level 1

3,960 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

19 Feb
1 month ago

programmer111 left a reply on Data Is Not Saving Into Db

@SERGIU17 - @mushood

can u plz check it, [email protected] pass= 123456

programmer111 left a reply on Data Is Not Saving Into Db

@MUSHOOD - sory bro still same issue

programmer111 left a reply on Data Is Not Saving Into Db

@SERGIU17 - Sorry, the page you are looking for could not be found. /public/admin/categories

programmer111 left a reply on Data Is Not Saving Into Db

@SERGIU17 - i changed the get to post, now it return me to the index when click on submit but still data is not submitting into db

programmer111 left a reply on Data Is Not Saving Into Db

@SERGIU17 - index is to show data from the db

programmer111 left a reply on Data Is Not Saving Into Db

@SNAPEY - nowhere, actually its first time that m using the resource controller, and all of my routes are working fine except this form submitting https://ibb.co/47GhF7s

programmer111 started a new conversation Data Is Not Saving Into Db

hi m trying to save data into db but it shows error page and says "no message"

code of controller (resource controller):

  public function create()
{
    return view('admin.categories.create');
}


public function store(Request $request)
{
    if ($request->isMethod('post')) {
        $data = $request->all();
        $category = new Category;
        $category->name = $data['category_name'];
        $category_description = $data['description'];
        $category->save();
    }
    return view('admin.categories.index');
}

create.blade.php

  <form class="k-form" method="post" action="{{ url('/admin/categories/index')}}" name="" 
    id="k_form">@csrf
                <div class="row">
                    <div class="col-xl-2"></div>
                    <div class="col-xl-8">
                        <div class="k-section k-section--first">
                        </div>
                        <div class="k-separator k-separator--border-dashed k-separator--space-lg"></div>
                        <div class="k-section">
                            <div class="k-section__body">
                                <h3 class="k-section__title k-section__title-lg">Add Category:</h3>
                                <div class="form-group row">
                                    <label class="col-3 col-form-label">Category Name:</label>
                                    <div class="col-9">
                                        <input class="form-control" type="text" name="category_name" value="" 
                required="required">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label class="col-3 col-form-label">Description:</label>
                                    <div class="col-9">
                                        <textarea name="description" required="required"></textarea>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label class="col-3 col-form-label"></label>
                                    <div class="col-9">
                                        <div class="k-checkbox-single">
                                            <input type="submit" value="Add Category" style="background-color: #5867dd; 
         color: #fff; border-radius: 5px; padding: 10px;" name="">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="k-separator k-separator--border-dashed k-separator--space-lg"></div>
                    </div>
                    <div class="col-xl-2"></div>
                </div>
            </form>

Route:

  Route::match(['get', 'post'],'/admin/categories/create','[email protected]');
15 Feb
1 month ago

programmer111 left a reply on Route Isn't Working

@TOMOPONGRAC - yes AdminAuthenticated.php

  public function handle($request, Closure $next)
{
    if(Auth::user()->role->name == 'customer'){
        return redirect('/home')->with('message', "You are Not Allowed To Access");
    }
    return $next($request);
}

updated RedirectIfAuthenticated.php:

  public function handle($request, Closure $next, $guard = null)
  {
    if (Auth::guard($guard)->check()) {
        if(Auth::user()->role->name == 'admin')
            return redirect('/admin');
        else
            return redirect('/home');
    }

    return $next($request);
  }

programmer111 left a reply on Route Isn't Working

@SNAPEY - admin page which was working fine then i add the middleware, and now it's not working, the request m using is "localhost/laravel/ecom3/public/admin"

programmer111 left a reply on Route Isn't Working

@TOMOPONGRAC - same error

this is route list:

  +--------+----------+------------------------+------------------+------------------------------------------------------------------------+----------------+

| Domain | Method | URI | Name | Action | Middleware | +--------+----------+------------------------+------------------+------------------------------------------------------------------------+----------------+ | | GET|HEAD | / | | Closure | web | | | GET|HEAD | admin/dashboard | admin.dashboard | App\Http\Controllers\[email protected] | web,auth,admin | | | GET|HEAD | api/user | | Closure | api,auth:api | | | GET|HEAD | home | home | App\Http\Controllers\[email protected] | web,auth | | | GET|HEAD | login | login | App\Http\Controllers\Auth\[email protected] | web,guest | | | POST | login | | App\Http\Controllers\Auth\[email protected] | web,guest | | | POST | logout | logout | App\Http\Controllers\Auth\[email protected] | web | | | POST | password/email | password.email | App\Http\Controllers\Auth\[email protected] | web,guest | | | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\[email protected] | web,guest | | | POST | password/reset | password.update | App\Http\Controllers\Auth\[email protected] | web,guest | | | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\[email protected] | web,guest | | | GET|HEAD | register | register | App\Http\Controllers\Auth\[email protected] | web,guest | | | POST | register | | App\Http\Controllers\Auth\[email protected] | web,guest | +--------+----------+------------------------+------------------+------------------------------------------------------------------------+----------------+

programmer111 started a new conversation Route Isn't Working

hi initially it was working but when i add middleware in it (, 'middleware'=>['auth','admin'], 'prefix'=>'admin') then it says page not found:

Route::group(['as'=>'admin.', 'middleware'=>['auth','admin'], 'prefix'=>'admin'], function () {

    Route::get('/admin/dashboard','[email protected]')->name('dashboard');

});
12 Feb
1 month ago

programmer111 started a new conversation Call To Undefined Method Barryvdh\Debugbar\Facade::isDeferred()

hi i install the debugger pulgin into my laravel project, initially it was working fine but now its showing the error:

  Call to undefined method Barryvdh\Debugbar\Facade::isDeferred()

how to resolve this issue

05 Feb
1 month ago

programmer111 left a reply on Data Is Inserting In Db But Displaying Error

@REALRANDYALLEN - data is submiting into db or using submitted data a user can also login, when i signup then data is submit into db but it shows this https://ibb.co/YLv6N5g this is controller https://paste.ofcode.org/RGqpftRqp9m4DFg6YfWGH3 this is login_register.blade.php https://paste.ofcode.org/4aWQTMsZ4mqTT4MrQqZe5

and route is:

  Route::post('/user-register','[email protected]');

programmer111 left a reply on Data Is Inserting In Db But Displaying Error

@REALRANDYALLEN - when i signup a new account then this error comes (data also inserts into db)

programmer111 started a new conversation Data Is Inserting In Db But Displaying Error

hi m working on user login_register from, when i signup then data inserts into db (and can also login), but browser says:

  maximum execution time of 30 seconds exceeded

in \vendor\phpunit\phpunit\appveyor.yml: its already 1200

  - IF NOT EXIST php-installed.txt echo max_execution_time=1200 >> php.ini

any solution to resolve this issue

30 Jan
1 month ago

programmer111 left a reply on Checkout Form Isn't Submitting

@TRAY2 - it showing this https://ibb.co/KGkWBhq mean the values of form are coming but cart values are not coming

programmer111 left a reply on Checkout Form Isn't Submitting

@SNAPEY - SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'product_id' cannot be null (SQL: insert into orders (name, email, address, country, state, city, zipcode, mobile, product_id, product_code, product_name, product_price, product_qty, order_status, grand_total, updated_at, created_at) values

programmer111 left a reply on Checkout Form Isn't Submitting

@SNAPEY - u can see it https://ibb.co/vXnJhQN

in whole scenrio m getting the cart values in checkout page and also enter the order data in it then it shows the above error ,

the screnshot of checkout page is https://ibb.co/P5JYszC

whole of data i mean cart data and user order has to store in this table https://ibb.co/bbBHCky

complete cart.blade.php https://paste.ofcode.org/34jcNT6uF9jm88mkQSH3Xub

productscontroller: https://paste.ofcode.org/UPqyBBCbbqtCpV8XGMpHHx

naw plz anyone can tel me the real issue

programmer111 left a reply on Checkout Form Isn't Submitting

@TRAY2 - sory still same error after removing this line

29 Jan
1 month ago

programmer111 left a reply on Checkout Form Isn't Submitting

@TRAY2 - thnx added it but still same error

programmer111 left a reply on Checkout Form Isn't Submitting

@SNAPEY - i updated my ProductsController to:

    public function placeOrder(Request $request){
      if($request->isMethod('post')){
         $data = $request->all();

        $session_id = Session::get('session_id');
         if(empty($session_id)){
            $session_id = str_random(40);
            Session::put('session_id',$session_id);
         }

          $order = new Order;
          $order->id = $request->id;
          $order->name = $request->name;
          $order->email = $request->email;
          $order->address = $request->address;
          $order->country = $request->country;
          $order->state = $request->state;
          $order->city = $request->city;
          $order->zipcode = $request->zipcode;
          $order->mobile = $request->mobile;
          $order->product_id = $request->product_id;
          $order->product_code = $request->product_code;
          $order->product_name = $request->product_name;
          $order->product_price = $request->product_price;
          $order->product_qty = $request->product_qty;
          $order->order_status = "New";
          $order->grand_total = $request->data['grand_total'];
          $order->save();

        return view('products.checkout');

      }
  }

once the data submitted with showing this error:

  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null (SQL: insert 
  into `orders` 

https://ibb.co/vXnJhQN

and now againg only showing above error

programmer111 left a reply on Checkout Form Isn't Submitting

@TRAY2 - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_quantity' in 'field list' (SQL: insert into orders (id, name, email, address, country, state, city, zipcode, mobile, product_id, product_code, product_name, product_price, product_quantity, order_status, grand_total, updated_at, created_at) values (, user, [email protected], 1234 main, usa, cal, lhr, 1234, 1234567, , , , , , New, , 2019-01-29 19:20:02, 2019-01-29 19:20:02))

and plz see it once https://ibb.co/bbBHCky

programmer111 left a reply on Checkout Form Isn't Submitting

@CRONIX - yes dd() showing the data

programmer111 left a reply on Checkout Form Isn't Submitting

@CRONIX - i changed the /checkout, to /place-order but still same issue

programmer111 left a reply on Checkout Form Isn't Submitting

@PAZITRON - no error and nthing happening

programmer111 started a new conversation Checkout Form Isn't Submitting

I'm new to laravel and first time working on ecom site and trying to submit the checkout form, but it is not submitting. It has values of products form cart (product name, code, price) and currently entered user data, and screenshot of DB table (orders) https://ibb.co/bbBHCky

checkout.blade.php

      <ul class="list-group mb-3">
      <?php  $total_amount = 0; ?>
      @foreach($userCart as $cart)
       <li class="list-group-item d-flex justify-content-between lh-condensed">
         <div>
            <h6 class="my-0">{{ $cart->product_name }}</h6>
            <small class="text-muted">Quantity: {{ $cart->quantity }}</small>
            <small class="text-muted" style="display: none;">{{ $cart->product_code }}</small>
            <small class="text-muted" style="display: none;">{{ $cart->product_id }}</small>
        </div>
        <span class="text-muted">Rs {{ $cart->price }}</span>
    </li>
   @endforeach
  <li class="list-group-item d-flex justify-content-between">
    <span>Total (PKR)</span>
    <strong>{{ $total }}</strong>
   </li>
  </ul>

  <form method="post" action="{{ url('/checkout') }}" class="needs-validation" novalidate>{{ 
  csrf_field() }}
    <div class="row">
    <div class="col-md-6 mb-3">
        <label for="firstName">Name</label>
        <input type="text" name="name" class="form-control" id="firstName" 
placeholder="name" value="" required
               style="border: 1px solid black !important;">
        <div class="invalid-feedback">
            Valid first name is required.
        </div>
    </div>
</div>

<div class="mb-3">
    <label for="email">Email </label>
    <input type="email" name="email" class="form-control" id="email" 
 placeholder="[email protected]"
           required="required" style="border: 1px solid black !important;">
    <div class="invalid-feedback">
        Please enter a valid email address for shipping updates.
    </div>
</div>

<div class="mb-3">
    <label for="address">Address</label>
    <input type="text" name="address" class="form-control" id="address" placeholder="1234 
  Main St" required
           style="border: 1px solid black !important;">
    <div class="invalid-feedback">
        Please enter your shipping address.
    </div>
  </div>

  <div class="row">
     <div class="col-md-5 mb-3">
        <label for="country">Country</label>
        <select name="country" class="custom-select d-block w-100" id="country" required>
            <option value="">Choose...</option>
            <option value="usa">United States</option>
        </select>
        <div class="invalid-feedback">
            Please select a valid country.
        </div>
    </div>
    <div class="col-md-4 mb-3">
        <label for="state">State</label>
        <select name="state" class="custom-select d-block w-100" id="state" required>
            <option value="">Choose...</option>
            <option value="cal">California</option>
        </select>
        <div class="invalid-feedback">
            Please provide a valid state.
        </div>
    </div>
    <div class="col-md-5 mb-3">
        <label for="country">City</label>
        <select name="city" class="custom-select d-block w-100" id="country" required>
            <option value="">Choose...</option>
            <option value="lhr">United States</option>
        </select>
        <div class="invalid-feedback">
            Please select a valid country.
        </div>
    </div>
    <div class="col-md-3 mb-3">
        <label for="zip">Zip</label>
        <input type="text" name="zipcode" class="form-control" id="zip" placeholder="" required
               style="border: 1px solid black !important;">
        <div class="invalid-feedback">
            Zip code required.
        </div>
    </div>
    <div class="col-md-5 mb-3">
        <label for="zip">Mobile</label>
        <input type="text" name="mobile" class="form-control" id="zip" placeholder="" required
               style="border: 1px solid black !important;">
        <div class="invalid-feedback">
            mobile no required.
        </div>
     </div>
  </div>

      <button class="btn btn-primary btn-lg btn-block" type="submit" style="background-color: 
   black;">Place Order</button>
  </form>

code of ProductsController:

  public function placeOrder(Request $request)
   {
    if ($request->isMethod('post')) {
    $data = $request->all();

     $session_id = Session::get('session_id');
      if (empty($session_id)) {
        $session_id = str_random(40);
        Session::put('session_id', $session_id);
    }

    $order = new Order;
    $order->id = $id;
    $order->name = $name;
    $order->email = $email;
    $order->address = $address;
    $order->country = $country;
    $order->state = $state;
    $order->city = $city;
    $order->zipcode = $zipcode;
    $order->mobile = $mobile;
    $order->product_id = $product_id;
    $order->product_code = $product_code;
    $order->product_name = $product_name;
    $order->product_price = $product_price;
    $order->product_quantity = $qty;
    $order->order_status = "New";
    $order->grand_total = $data['grand_total'];
    $order->save();

      return view('products.checkout');
    }  
  }

and route is:

  Route::match(['get','post'],'/place-order','[email protected]');
27 Jan
1 month ago

programmer111 started a new conversation SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'product_id' Cannot Be Null (SQL: Insert Into `cart` (`product_id`, `product_name`, `product_code`, `product_color`, `price`, `size`, `quantity`, `user_email`, `session_id`)

m trying to add to cart a product nut when i click on add to cart button on detail.blade.php page then it shows this error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'product_id' cannot be null (SQL: insert into cart (product_id, product_name, product_code, product_color, price, size, quantity, user_email, session_id) values (, Filter, ASD111, White, 5000, Choose an option, 1, , )) any solution to resolve this issue

here is detail.blade.php:

  <form name="addtocartForm" id="addtocartForm" action="{{ url('add-cart') }}" 
  method="post">
            {{ csrf_field() }}
            <input type="hidden" name="product_id" value="{{ $productDetails->product_id }}">
            <input type="hidden" name="product_name" value="{{ $productDetails- 
     >product_name }}">
            <input type="hidden" name="product_code" value="{{ $productDetails->product_code 
   }}">
            <input type="hidden" name="product_color" value="{{ $productDetails- 
   >product_color }}">
            <input type="hidden" name="price" value="{{ $productDetails->price }}">
          <div class="w-size14 p-t-30 respon5">
            <h4 class="product-detail-name m-text16 p-b-13">
                {{ $productDetails->product_name }}
            </h4>

            <span class="m-text17">
                PKR: {{ $productDetails->price }}
            </span>
  </form>

code of ProductsController:

  public function addtocart(Request $request){
  $data = $request->all();
  //echo "<pre>"; print_r($data); die;

  if(empty($data['user_email'])){
    $data['user_email'] = '';
  }

  if(empty($data['session_id'])){
    $data['session_id'] = '';
  }

  DB::table('cart')->insert(['product_id'=>$data['product_id'],
  'product_name'=>$data['product_name'],
  'product_code'=>$data['product_code'],
  'product_color'=>$data['product_color'],
  'price'=>$data['price'],
  'size'=>$data['size'],'quantity'=>$data['quantity'],
  'user_email'=>$data['user_email'],
  'session_id'=>$data['session_id']]);
  }

route:

  Route::match(['get','post'], '/add-cart','[email protected]');
25 Jan
1 month ago

programmer111 started a new conversation Contact Data Isnt Showing From Db

m trying to show contact data of site on admin panel but it says page not found. the main thing is to show contact data at admin panel

here is code of ContactController:

  public function viewContact(){
    $contact = Contact::get();
    return view('admin.contacts.view_contacts')->with(compact('contact'));
  }

code of view_contacts.blade.php:

  @foreach($contacts as $contact)
    <div class="control-group">
      <label class="control-label">{{ $contact->name }}</label>
      <div class="controls">
        <input type="text" class="span11" placeholder="First name" />
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">{{ $contact->email }}</label>
      <div class="controls">
        <input type="text" class="span11" placeholder="First name" />
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">{{ $contact->subject }}</label>
      <div class="controls">
        <input type="text" class="span11" placeholder="Company name" />
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">Description</label>
      <div class="controls">
        <textarea class="span11" >{{ $contact->description }}</textarea>
      </div>
    </div>
    @endforeach

route:

  Route::get('/admin/contact','[email protected]');

and the display when i click on contacts is:https://ibb.co/sbqRQXL

24 Jan
2 months ago

programmer111 started a new conversation Data Is Not Submitting Into Db

m making a contact page but from contact page data is not saving into db

this is code of ContactController.php:

  public function contact(){

    if($request->isMethod('post')){
        $data = $request->all();
    }

    $contact = new Contact;
        $contact->name = $data['contact_name'];
        $contact->email = $data['contact_email'];
        $contact->subject = $data['contact_subject'];
        $contact->body = $data['description'];
        $category->save();
    return redirect()->back()->with('flash_message_success', 'Your message has been sent 
    successfully');
  }

this is contact.blade.php

  <form action="{{ url('/contact') }}" id="main-contact-form" class="contact-form row" 
     name="contact-form" method="post">{{ csrf_field() }}
                        <div class="form-group col-md-6">
                            <input type="text" name="contact_name" class="form-control" 
   required="required" placeholder="Name">
                        </div>
                        <div class="form-group col-md-6">
                            <input type="email" name="contact_email" class="form-control" 
     required="required" placeholder="Email">
                        </div>
                        <div class="form-group col-md-12">
                            <input type="text" name="contact_subject" class="form-control" 
    required="required" placeholder="Subject">
                        </div>
                        <div class="form-group col-md-12">
                            <textarea name="description" id="message" required="required" 
   class="form-control" rows="8" placeholder="Your Message Here"></textarea>
                        </div>                        
                        <div class="form-group col-md-12">
                            <input type="submit" name="submit" class="btn btn-primary pull- 
  right" value="Submit">
                        </div>
                    </form>

and these are the routes:

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

  Route::post('contact', function () {
   return view('contact');
  });

programmer111 left a reply on Image Is Not Displaying In Front-end While Saving In Destination Folder

@CIPSAS - i hv added 3 images to this product 1 is stored in this destination: the actual path of the folder where the images are storing is: D:\xampp\htdocs\laravel\laraecom\storage\app\public\moreImagesFolders\1548330753

and the other is:

D:\xampp\htdocs\laravel\laraecom\storage\app\public\images

programmer111 started a new conversation Image Is Not Displaying In Front-end While Saving In Destination Folder

m working on ecommerce site, when i add product then it show on index page without image but image is saving in the destination folder, can anyone provide solution fot it,

code of ProductsController:

  public function productPreview(Request $request)
{
    $productsModel = new ProductsModel();
    $product = $productsModel->getProduct($request->id);
    if ($product == null) {
        abort(404);
    }

    $gallery = array();
    if ($product->folder != null) {
        $dir = '../storage/app/public/moreImagesFolders/' . $product->folder . '/';
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                $i = 0;
                while (($file = readdir($dh)) !== false) {
                    if (is_file($dir . $file)) {
                        $gallery[] = asset('storage/moreImagesFolders/' . $product->folder . '/' . $file);
                    }
                    $i++;
                }
                closedir($dh);
            }
        }
    }

    return view('publics.preview', [
        'product' => $product,
        'cartProducts' => $this->products,
        'head_title' => mb_strlen($product->name) > 70 ? str_limit($product->name, 70) : $product->name,
        'head_description' => mb_strlen($product->description) > 160 ? str_limit($product->description, 160) : $product->description,
        'gallery' => $gallery
    ]);
}

programmer111 started a new conversation Trying To Get Property 'name' Of Non-object

When i delete the sub category(having products) of main category then it deletes but when i click on view-products then it says: Trying to get property 'name' of non-object, and showing the error line in ProductsController which is: $category_name = Category::where(['id' => $val->category_id])->first(); $products[$key]->category_name = $category_name->name; }

here is code of ProductsController:

  public function viewProducts(Request $request){
    $products = Product::get();
    foreach($products as $key => $val){
        $category_name = Category::where(['id' => $val->category_id])->first();
        $products[$key]->category_name = $category_name->name;
    }
    $products = json_decode(json_encode($products));
    //echo "<pre>"; print_r($products); die;
    return view('admin.products.view_products')->with(compact('products'));
}

any solution about it,

22 Jan
2 months ago

programmer111 left a reply on Undefined Index: Category_id

@CIPSAS - that error came on random checking code and now this is last error

programmer111 left a reply on Undefined Index: Category_id

@CIPSAS - without editing the description image is editing fine: it shows more errors on editing, this is cmplte function:

  public function editProduct(Request $request, $id=null){

  if($request->isMethod('post')){
    $data = $request->all();
    //echo "<pre>"; print_r($data); die;


     if($request->hasFile('image')){
      $image_tmp = Input::file('image');
      if($image_tmp->isValid()){
        $extension = $image_tmp->getClientOriginalExtension();
        $filename = rand(111,99999).'.'.$extension;
        $large_image_path = 'images/backend_images/products/large/'.$filename;
        $medium_image_path = 'images/backend_images/products/medium/'.$filename;
        $small_image_path = 'images/backend_images/products/small/'.$filename;
        // Resize Images
        Image::make($image_tmp)->save($large_image_path);
        Image::make($image_tmp)->resize(600,600)->save($medium_image_path);
        Image::make($image_tmp)->resize(300,300)->save($small_image_path);

        // Store image name in products table
        $product = $filename;
        }
       } 

    if(empty($data['description'])){
          $data['description'] = '';
        }

     Product::where(['id'=>$id])->update([
     ['category_id'=>data_get($data, 'category_id')],
     'product_name'=>$data['product_name'],
     'product_code'=>$data['product_code'],
     'product_color'=>$data['product_color'],
      'description'=>$data['description'],
      'price'=>$data['price'],
      'image'=>$filename]);
     return redirect()->back()->with('flash_message_success','Product updated successfully!');
  }
  //Get product details
  $productDetails = Product::where(['id'=>$id])->first();

programmer111 left a reply on Undefined Index: Category_id

@CIPSAS - now it showing Undefined variable: filename

programmer111 left a reply on Undefined Index: Category_id

@CIPSAS - can u tell me what to go

programmer111 started a new conversation Undefined Index: Category_id

hi, m trying to edit description of product but it says: "Undefined index: category_id"

this is productscontroller where its showing error:

 Product::where(['id'=>$id])->update(['category_id'=>$data['category_id'],
 'product_name'=>$data['product_name'],
 'product_code'=>$data['product_code'],
 'product_color'=>$data['product_color'],
 'description'=>$data['description'],
 'price'=>$data['price'],'image'=>$filename]);
    return redirect()->back()->with('flash_message_success','Product updated successfully!');

anyone can solve this issue

20 Jan
2 months ago

programmer111 left a reply on All Categories Are Not Showing In Header From Db

@SNAPEY - no issue of html/css

  <div class="btn-group">
  <a href="{{ url('/shop')}}" class="btn btn-info">Categories</a>
  <button type="button" class="btn btn-info dropdown-toggle dropdown-toggle-split" data- 
  toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  <span class="sr-only">Toggle Dropdown</span>
  </button>
  @foreach($mainCategories as $cat)
  <div class="dropdown-menu">
  <a class="dropdown-item" href="{{ asset('products/'.$cat->url) }}">{{ $cat->name }}</a>
  </div>
  @endforeach
  </div>

"in tinker all the three cayegories are showing"

and still same results with Category::where('parent_id', 0)->get();

programmer111 left a reply on All Categories Are Not Showing In Header From Db

@SNAPEY - actually m trying to get all main categories in the header (which contains the products related to them) but only one is coming, here is link of pic of admin panel where records are coming from db:

https://imageshack.com/i/plRp0Inbp

and here is link of pic of index page where only 1 category is showing:

https://imageshack.com/i/plIIRDDBp

and can u plz provide any solution to resolve it. and sory actually i was just checking about values so i write json_decode json_encode, its still working without it, i hv comment it and updated it above,