AndreLan

AndreLan

Member Since 2 Months Ago

Experience Points 720
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Answer
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.

13 Nov
3 weeks ago

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@SNAPEY - I used this if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) { // The user is active, not suspended, and exists. } and I checked SQL query with Laravel Debugbar and I found that login check isn't using that code at all !!

12 Nov
3 weeks ago

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@TPANE24 - never mind, but unfortunately, user can log in also

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@SNAPEY - ok, I did everything as you said and still have the same issue, the user can normally login

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@SNAPEY - ok, it is an integer, I was sure but I had to check, I changed it to Boolean but it changed to tinyint(1)

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@SNAPEY - ok I will check this and try again

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@TPANE24 - I did not find this function, I have AuthController, not LoginController so it contains

use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

and Auth\AuthenticatesAndRegistersUsers contains

<?php

namespace Illuminate\Foundation\Auth;

trait AuthenticatesAndRegistersUsers
{
    use AuthenticatesUsers, RegistersUsers {
        AuthenticatesUsers::redirectPath insteadof RegistersUsers;
        AuthenticatesUsers::getGuard insteadof RegistersUsers;
    }
}

and AuthenticatesUsers contains

<?php

namespace Illuminate\Foundation\Auth;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;

trait AuthenticatesUsers
{
    use RedirectsUsers;

    /**
     * Show the application login form.
     *
     * @return \Illuminate\Http\Response
     */
    public function getLogin()
    {
        return $this->showLoginForm();
    }

    /**
     * Show the application login form.
     *
     * @return \Illuminate\Http\Response
     */
    public function showLoginForm()
    {
        $view = property_exists($this, 'loginView')
                    ? $this->loginView : 'auth.authenticate';

        if (view()->exists($view)) {
            return view($view);
        }

        return view('auth.login');
    }

    /**
     * Handle a login request to the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function postLogin(Request $request)
    {
        return $this->login($request);
    }

    /**
     * Handle a login request to the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function login(Request $request)
    {
        $this->validateLogin($request);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        $throttles = $this->isUsingThrottlesLoginsTrait();

        if ($throttles && $lockedOut = $this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        $credentials = $this->getCredentials($request);

        if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) {
            return $this->handleUserWasAuthenticated($request, $throttles);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        if ($throttles && ! $lockedOut) {
            $this->incrementLoginAttempts($request);
        }

        return $this->sendFailedLoginResponse($request);
    }

    /**
     * Validate the user login request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return void
     */
    protected function validateLogin(Request $request)
    {
        $this->validate($request, [
            $this->loginUsername() => 'required', 'password' => 'required',
        ]);
    }

    /**
     * Send the response after the user was authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  bool  $throttles
     * @return \Illuminate\Http\Response
     */
    protected function handleUserWasAuthenticated(Request $request, $throttles)
    {
        if ($throttles) {
            $this->clearLoginAttempts($request);
        }

        if (method_exists($this, 'authenticated')) {
            return $this->authenticated($request, Auth::guard($this->getGuard())->user());
        }

        return redirect()->intended($this->redirectPath());
    }

    /**
     * Get the failed login response instance.
     *
     * @param \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    protected function sendFailedLoginResponse(Request $request)
    {
        return redirect()->back()
            ->withInput($request->only($this->loginUsername(), 'remember'))
            ->withErrors([
                $this->loginUsername() => $this->getFailedLoginMessage(),
            ]);
    }

    /**
     * Get the failed login message.
     *
     * @return string
     */
    protected function getFailedLoginMessage()
    {
        return Lang::has('auth.failed')
                ? Lang::get('auth.failed')
                : 'These credentials do not match our records.';
    }

    /**
     * Get the needed authorization credentials from the request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    protected function getCredentials(Request $request)
    {
        return $request->only($this->loginUsername(), 'password');
    }

    /**
     * Log the user out of the application.
     *
     * @return \Illuminate\Http\Response
     */
    public function getLogout()
    {
        return $this->logout();
    }

    /**
     * Log the user out of the application.
     *
     * @return \Illuminate\Http\Response
     */
    public function logout()
    {
        Auth::guard($this->getGuard())->logout();

        return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
    }

    /**
     * Get the guest middleware for the application.
     */
    public function guestMiddleware()
    {
        $guard = $this->getGuard();

        return $guard ? 'guest:'.$guard : 'guest';
    }

    /**
     * Get the login username to be used by the controller.
     *
     * @return string
     */
    public function loginUsername()
    {
        return property_exists($this, 'username') ? $this->username : 'email';
    }

    /**
     * Determine if the class is using the ThrottlesLogins trait.
     *
     * @return bool
     */
    protected function isUsingThrottlesLoginsTrait()
    {
        return in_array(
            ThrottlesLogins::class, class_uses_recursive(static::class)
        );
    }

    /**
     * Get the guard to be used during authentication.
     *
     * @return string|null
     */
    protected function getGuard()
    {
        return property_exists($this, 'guard') ? $this->guard : null;
    }
}

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@SNAPEY - I got this

    >>> App\User::find(10)->status

=> "1"

App\User::find(9)->status => "2"

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@SNAPEY - Sorry for being late, I had exams..

I tried User::find(1)->active and the user can login also..

can I do this by middleware instead of AuthController ??

09 Nov
1 month ago

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

Is there anyway else instead of this to disable user login or ban a user account if it is inactive

08 Nov
1 month ago

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@SIANGBOON - I checked this also and found that the admin who I use is the one who hit the function, and the user was changed to inactive ( 0 in the database) but can log in normally and use all functions normally

07 Nov
1 month ago

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@SNAPEY - yes and the user account still working normally .. 0 is the same as 1

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@SNAPEY - when you log in as an admin and change a user status to inactive it will be changed and also in the database but when you try to log in with this account it will work normally as it is active and nothing changed but actually it was changed even in the database

AndreLan left a reply on Manually Authenticating Users And Ban Function Not Working

@WILK_RANDALL - I checked and found that it is not active and can do everything as it is active although it is recorded as not active in the database

AndreLan started a new conversation Manually Authenticating Users And Ban Function Not Working

I am using laravel 5.2 and I wrote this function in the AuthController but it doesn't work at all

public function authenticate()
{
if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
    // The user is active, not suspended, and exists.
    return redirect()->intended('/');// return $next($request);
        }
        else {
        return redirect('/login');// return response('Unauthorized.', 401);
            }
}

what is the wrong with it

30 Oct
1 month ago

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

@arthvrian the last 3 lines on cancel_qty are the rest of the old code :) ..., seriously I forgot removing them :D ..., In the view, you are right I made it @else without ($order->qty > 1), it is logical :) ..., @elseif ($order->qty > 1) //must be only @else and I can't use it for updating because I am using another function to do that and it is completely different, also I prefer to make this with another button which increases the qty, but the second one is only decreasing the qty. Now I have a new problem which is repeating the item if you updated its qty or added it again from the home view, I want to make it only one item with its qty if it was increased, not repeating it every time you increase qty...

29 Oct
1 month ago

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

cart view

@if ($order->qty == 1)
<a href="/cancel_order/{{ $order['id'] }}" class="link1">Cancel</a>
@elseif ($order->qty > 1)
<a href="/cancel_qty/{{ $order['id'] }}" class="link1">Cancel</a>
@endif 

OrderController

public function cancel_order($id)
    {
    $order = Order::find($id);
    $product= Product::find($order->product_id);
    $product->inv = $product->inv + 1;
    $product->save();
    $order->delete();
    return redirect('/my_cart');
    }


public function cancel_qty(Request $request, $id)
    {
    $validator = Validator::make($request->all(), [
        'qty' => 'required|max:255',
        
    ]);
    $order = Order::find($id);
    $product= Product::find($order->product_id);
    if ($request->input('qty') > $order->qty) {
        return redirect('/my_cart')
                    ->withErrors($validator)
                    ->withInput();
    }
    if ($request->input('qty') < $order->qty) {
    $order->qty = $order->qty - $request['qty'];
    $product->inv = $product->inv + $request->input('qty');
    $order->save();
    $product->save();
    return redirect('/my_cart');
    }elseif
          ($request->input('qty') == $order->qty) {
          $order->delete();
          $product->inv = $product->inv + $request->input('qty');
          $product->save();
          return redirect('/my_cart');
          }
    $product->save();
    $order->save();
    return redirect('/my_cart');
    }

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

@shez1983 @arthvrian Thanks for your consideration :) ... I solved it finally

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

@Snapey Thanks for your consideration, although your code did not work with me it helped to think out of the box or( out of the OrderController ), I did what I want in the cart view and It worked :) .. I will write the code...

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

@jlrdw Thanks a lot, I will check that very soon, I am sure I will need it later

28 Oct
1 month ago

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

@jlrdw I thought about the first idea and tested it and the problem is when you delete the order with that special button you will lose the quantity and the product will not be increased, it will lose its inventory that was deleted permanently from the orders' cart..

then I canceled this idea...

a friend told me to hide the item if it = 0 by js, but I don't know how to do that, honestly I am not good at js, also I see that this is not a solution, because it still actually exists in the cart.

So how to use a code that ignores a 0 quantity..?

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

Nooo, It deletes the order permanently,

qty = 4, order qty = 6, delete everything

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

@Snapey I told you I tried what you said before asking..., I tried dd() and it gave me true when deleting the value of the item's qty and the item stayed with qty=0, and the product increased by the same value you typed to delete from the order, it means that everything is ok, and I checked if the order was being loaded is the correct one, and about your code

if ($request->input('qty') >= $order->qty {

    // deleting the same or more than the quantity ordered
    // therefore order is no longer required

    $order->delete();
    return redirect('/my_cart')
    }

it caused deleting the item with ignoring the value you typed whether less or more than the item's qty

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

@shez1983

public function destroy(Request $request, $id)
        {
        $validator = Validator::make($request->all(), [
            'qty' => 'required|max:255',
            
        ]);
        $order = Order::find($id);

    // this to prevent negative values because after deleting all quantities of an item,
// the item stays in the cart with qty=0, so if you typed any number it will count with
// negative values and the product will be increased, I didn't get any idea to prevent that except this trick.
        if ($request->input('qty') > $order->qty) {
            return redirect('/my_cart')
                        ->withErrors($validator)
                        ->withInput();
        }

// I tried this to get rid of the items with qty=0 by deleting them permanently if you
// typed a value=the existing qty or if the qty=1 and you clicked delete
// but I got this error (Can't use method return value in write context)
// when opening the cart view.
        // if ($request->input('qty') = $order->qty || $request->input('qty') = 1) {
        //     return redirect('/my_cart')
        //                 ->delete();
        // }

// I tried this also for the same reason but I got this error
// (Trying to get property of non-object) when deleting.
        // $order = Order::where('qty','=',$request->input('qty'))->delete();        
        
// this is to increase the product inventory with the
// value you typed to delete from orders
        $product= Product::find($order->product_id);
        $product->inv = $product->inv + $request->input('qty');

// this is to delete only the qty you typed if you typed
// a value less than the existing qty of the item.
    $order->qty = $order->qty - $request['qty'];
        
        $product->save();
        $order->save();
        
        return redirect('/my_cart');

    }

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

@shez1983

public function destroy(Request $request, $id) { $validator = Validator::make($request->all(), [ 'qty' => 'required|max:255',

    ]);
    $order = Order::find($id);

// this to prevent negative values because after deleting all quantities of an item,

// the item stays in the cart with qty=0, so if you typed any number it will count with // negative values and the product will be increased, I didn't get any idea to prevent that except this trick. if ($request->input('qty') > $order->qty) { return redirect('/my_cart') ->withErrors($validator) ->withInput(); }

// I tried this to get rid of the items with qty=0 by deleting them permanently if you // typed a value=the existing qty or if the qty=1 and you clicked delete // but I got this error (Can't use method return value in write context) // when opening the cart view. // if ($request->input('qty') = $order->qty || $request->input('qty') = 1) { // return redirect('/my_cart') // ->delete(); // }

// I tried this also for the same reason but I got this error // (Trying to get property of non-object) when deleting. // $order = Order::where('qty','=',$request->input('qty'))->delete();

// this is to increase the product inventory with the // value you typed to delete from orders $product= Product::find($order->product_id); $product->inv = $product->inv + $request->input('qty');

// this is to delete only the qty you typed if you typed // a value less than the existing qty of the item. $order->qty = $order->qty - $request['qty'];

    $product->save();
    $order->save();
    
    return redirect('/my_cart');

}

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

@Snapey Thanks for the reply, but believe me, I wouldn't look out of the window hoping for someone on laracasts or anywhere else to do it for me before trying all what you said...

27 Oct
1 month ago

AndreLan left a reply on Can't Delete Items From Cart, Only Quantity And Leaving The Item With 0 Quantity

I tried two == and I have the same error (Can't use method return value in write context )

AndreLan started a new conversation How To Solve Problems Of Deleting From Orders Or Products

When I delete from the item's quantity it works fine, I just click on delete then a pop-up input form will appear then I write the quantity I want to delete then submit.. for example, I have a watch in my cart with quantity=20, when I want to delete 5 of them I have to write 5 then delete and after that I will have the same item of course with quantity=15, but when I write 15 to delete the whole order it only deletes the quantity and leaves the item with quantity=0, also if the quntity=1 I want to delete the item permanently when clicking delete, I do not need the pop-up input form to appear.. how to do that. I tried both of the commented methods but with no result, only errors.

this is my destroy function in OrderController

public function destroy(Request $request, $id)
        {
        $validator = Validator::make($request->all(), [
            'qty' => 'required|max:255',
            
        ]);
        $order = Order::find($id);
        if ($request->input('qty') > $order->qty) {
            return redirect('/my_cart')
                        ->withErrors($validator)
                        ->withInput();
        }


        // if ($request->input('qty') = $order->qty || $request->input('qty') = 1) {
        //     return redirect('/my_cart')
        //                 ->delete();
        // }

        // $order = Order::where('qty','=',$request->input('qty'))->delete();        
        

        $product= Product::find($order->product_id);
        $order->qty = $order->qty - $request['qty'];
        $product->inv = $product->inv + $request->input('qty');
        
        $product->save();
        $order->save();
        
        return redirect('/my_cart');

    }
11 Oct
1 month ago

AndreLan left a reply on How To Solve Problems Of Deleting From Orders Or Products

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Order;
use App\Product;
use Auth;
use App\User;
use App\Details;
use Validator;
use App\Cart;
use Session;

class OrderController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth');
    }

    public function my_cart()
    {
        $orders = Order::where('user_id','=',Auth::user()->id)->orderBy('id','desc')->get();
        return view('order.my_cart',compact('products','orders','users'));
    }   



  public function add_2_my_cart(Request $id)
    {
        $product = Product::find($id);
        // $product = Product::where('inv','=',$id)->get();
        return view('views.index',compact('product','order','user'));
    }


public function add_to_my_cart(Request $request, $id)
    

        {
        $validator = Validator::make($request->all(), [
            'qty' => 'required|max:255',
            
        ]);

        if ($validator->fails()) {
            return redirect('')
                        ->withErrors($validator)
                        ->withInput();
        }

        $product = Product::find($id);
        $order = new Order();

        $oldCart = Session::has('cart') ? Session::get('cart') : null;
        $cart = new Cart($oldCart);
        $cart->add($product, $product->id);
        $request->session()->put('cart',$cart);

        $order->user_id = Auth::user()->id;
        $order->product_id = $id;
        $order->qty = $request['qty'];
        $product->inv = $product->inv - $order->qty;
        $order->save();
        $product->save();
        return redirect('/');
    }
 
    
public function edit(Request $id)
    {
        $product = Product::find($id);
        // $product = Product::where('inv','=',$id)->get();
        return view('order.my_cart',compact('product','order','user'));
    }


public function update(Request $request, $id)
    

        {
        $validator = Validator::make($request->all(), [
            'qty' => 'required|max:255',
            
        ]);

        if ($validator->fails()) {
            return redirect('')
                        ->withErrors($validator)
                        ->withInput();
        }

        $product = Product::find($id);
        $order = new Order();

        $oldCart = Session::has('cart') ? Session::get('cart') : null;
        $cart = new Cart($oldCart);
        $cart->add($product, $product->id);
        $request->session()->put('cart',$cart);

        $order->user_id = Auth::user()->id;
        $order->product_id = $id;
        $order->qty = $request['qty'];
        $product->inv = $product->inv - $order->qty;
        $order->save();
        $product->save();
        return redirect('/my_cart');
    }


        public function delete($id)
    {
        $order = Order::find($id);
        // $product = Product::where('inv','=',$id)->get();
        return view('order.my_cart',compact('product','order','user'));
    }


          public function destroy(Request $request, $id)
        {
        $validator = Validator::make($request->all(), [
            'qty' => 'required|between:0,255',
            
        ]);

        if ($validator->fails()) {
            return redirect('')
                        ->withErrors($validator)
                        ->withInput();
        }
        $order = Order::find($id);
        $product= Product::find($order->product_id);
        $order->qty = $order->qty - $request['qty'];
        $product->inv = $product->inv + $request->input('qty');
        // if($order->qty == 1 || $order->qty){Order::destroy($id);}
        $product->save();
        $order->save();
        
        return redirect('/my_cart');

    }  
    
}

AndreLan left a reply on How To Solve Problems Of Deleting From Orders Or Products

@jekinney First of all, thank you for your reply.. I tried both of them and the same issue exactly..

AndreLan started a new conversation How To Solve Problems Of Deleting From Orders Or Products

I want something I do not know how to write it correctly, I want when a customer delete an order and it is only one order (quantity = 1), to be deleted permanently and also if he typed the same quantity, to be deleted permanently also because when I tested this function I found that it keeps deleting till 2, 1, 0, -1, -2, -3, etc.. and increases the product quantity

and I want if the product quantity is 0 to hide the product for all users except the admins and the seller who sold it or at least to hide the Add to Cart button for all or replace it with dead button with out of stock instead of Add to Cart and if a user already ordered some of this product he cannot update quantity but can cancel it then it will be added to products again..

and I hope if someone tells me how to use these spans when errors happened or not because I do not know how to do that also or how to edit the default laravel error messages thanks, again...

this is the OrderController destroy function

public function destroy(Request $request, $id)
            {
            $validator = Validator::make($request->all(), [
                'qty' => 'required|max:255',

            ]);

            if ($validator->fails()) {
                return redirect('')
                            ->withErrors($validator)
                            ->withInput();
            }
            $order = Order::find($id);
        $product= Product::find($order->product_id);
        $order->qty = $order->qty - $request->input('qty');
        $product->inv = $product->inv + $order->qty;
        $product->save();
        $order->save();
            return redirect('/myorders');

        }  

and this is the span messages I want to run

<span class="help-block">
                  <div class="success_message" style="display: block; text-align:center">Order Updated Successfully</div><br>
            </span>   
            <span class="help-block">  
                  <strong class="error_message" style="display: block; text-align:center">Sorry, Product Out of Stock, Try again later</strong>
            </span>
10 Oct
1 month ago

AndreLan left a reply on Relation Issue Between Orders Quantity And Products Inventory

Any help guys with this issue ???

09 Oct
2 months ago

AndreLan left a reply on Relation Issue Between Orders Quantity And Products Inventory

@Vilfago

I have 4 tables in my database (user_type_id , users , products and orders, orders table contains 4 columns (id , product_id , user_id and qty), user_id and product_id = foreign keys of users and products tables.

orders table contains

public function user()
    {
        return $this->belongsTo('App\User');
    }
    public function product()
    {
        return $this->belongsTo('App\Product');
    }

AndreLan started a new conversation Relation Issue Between Orders Quantity And Products Inventory

I want something I do not know how to write it correctly, I want when a customer delete an order and it is only one order (quantity = 1), to be deleted permanently and also if he typed the same quantity, to be deleted permanently also because when I tested this function I found that it keeps deleting till -1 -2 -3 etc..

and I want if the product quantity is 0 to hide the product for all users except the admins and the seller who sold it or at least to hide the Add to Cart button for all or replace it with dead button with out of stock instead of Add to Cart and if a user already ordered some of this product he cannot update quantity but can cancel it then it will be added to products again..

and I hope if someone tells me how to use these spans when errors happened or not because I do not know how to do that also :D thanks, again...

this is the OrderController destroy function

public function destroy(Request $request, $id)
            {
            $validator = Validator::make($request->all(), [
                'qty' => 'required|max:255',

            ]);

            if ($validator->fails()) {
                return redirect('')
                            ->withErrors($validator)
                            ->withInput();
            }
            $order = Order::find($id);
        $product= Product::find($order->product_id);
        $order->qty = $order->qty - $request->input('qty');
        $product->inv = $product->inv + $order->qty;
        $product->save();
        $order->save();
            return redirect('/myorders');

        }  

and this is the span messages I want to run

<span class="help-block">
                  <div class="success_message" style="display: block; text-align:center">Order Updated Successfully</div><br>
            </span>   
            <span class="help-block">  
                  <strong class="error_message" style="display: block; text-align:center">Sorry, Product Out of Stock, Try again later</strong>
            </span>
08 Oct
2 months ago

AndreLan left a reply on How To Solve (Trying To Get Property Of Non-object) Error, But The Same Function Works Well In Another Function

ok, thanks for all :) , I fixed it, It was the action of the view form :D action="/update_order/{{ $order['id'] }}" , It should be action="/update_order/{{ $order->product->id }}" ,,

Now :)

I want something I do not know how to write it correctly, I want when a customer delete an order and it is only one order (quantity = 1), to be deleted permanently and also if he typed the same quantity, to be deleted permanently also because when I tested this function I found that it keeps deleting till -1 -2 -3 etc..

and I want if the product quantity is 0 to hide the product for all users except the admins and the seller who sold it or at least to hide the Add to Cart button for all or replace it with dead button with out of stock instead of Add to Cart and if a user already ordered some of this product he cannot update quantity but can cancel it then it will be added to products again..

and I hope if someone told me how to use the commented spans because I do not know how to do that also :D thanks again..

AndreLan left a reply on Trying To Get Property Of Non-object But The Function Works Well In Another Function

@tykus yes, I understood, but using findOrFail($id) in place of find($id) for which function .. or for all of them?

AndreLan left a reply on Trying To Get Property Of Non-object But The Function Works Well In Another Function

@tykus

I do not understand where to use this or for doing what ??

AndreLan started a new conversation Trying To Get Property Of Non-object But The Function Works Well In Another Function

what is wrong with this controller, I always get this error when update order "Trying to get property of non-object" ,(notice that I'm using the same function for store and it works fine, also I want something I do not know how to write it correctly, I want when a customer delete an order and it is only one order (quantity = 1), to be deleted permanently and also if he typed the same quantity, to be deleted permanently also because when I tested this function and I found that it keeps deleting till -1 -2 -3 etc.. and I want if the product quantity is 0 to hide the product for all users except the admins and the seller who sold it or at least to hide the Add to Cart button for all or replace it with dead button with out of stock instead of Add to Cart and if a user already ordered some of this product he cannot update quantity but can cancel it then it will be added to products again.. and I hope if someone told me how to use the commented spans because I do not know how to do that also :D thanks

    namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    use App\Http\Requests;
    use App\Order;
    use App\Product;
    use Auth;
    use App\User;
    use App\Details;
    use Validator;
    
    class OrderController extends Controller
    {
    
        public function __construct()
        {
            $this->middleware('auth');
        }
    
        public function myorders()
        {
            $orders = Order::where('user_id','=',Auth::user()->id)->orderBy('id','desc')->get();
            return view('order.myorders',compact('products','orders','users'));
        }   
    
    
    
    
    
    
      public function buy(Request $id)
        {
            $product = Product::find($id);
            return view('product.index',compact('product','order','user'));
        }
    
    public function store(Request $request, $id)
        
    
            {
            $validator = Validator::make($request->all(), [
                'qty' => 'required|max:255',
                
            ]);
    
            if ($validator->fails()) {
                return redirect('')
                            ->withErrors($validator)
                            ->withInput();
            }
    
            $product = Product::find($id);
            $order = new Order();
            $order->user_id = Auth::user()->id;
            $order->product_id = $id;
            $order->qty = $request['qty'];
            $product->inv = $product->inv - $order->qty;
            $order->save();
            $product->save();
            return redirect('/');
        }
     
        
    public function edit(Request $id)
        {
            $product = Product::find($id);
            return view('order.myorders',compact('product','order','user'));
        }
    
    
    public function update(Request $request, $id)
        
    
            {
            $validator = Validator::make($request->all(), [
                'qty' => 'required|max:255',
                
            ]);
    
            if ($validator->fails()) {
                return redirect('')
                            ->withErrors($validator)
                            ->withInput();
            }
    
            
            $product = Product::find($id);
            $order = new Order();
            $order->user_id = Auth::user()->id;
            $order->product_id = $id;
            $order->qty = $request['qty'];                                  
  this line $product->inv = $product->inv - $order->qty; (it works in store)
            $order->save();
            $product->save();
    
            return redirect('/myorders');
        
        }
    
    
            public function delete($id)
        {
            $order = Order::find($id);
            return view('order.myorders',compact('product','order','user'));
        }
    
    
              public function destroy(Request $request, $id)
            {
            $validator = Validator::make($request->all(), [
                'qty' => 'required|max:255',
                
            ]);
    
            if ($validator->fails()) {
                return redirect('')
                            ->withErrors($validator)
                            ->withInput();
            }
            $order = Order::find($id);
        $product= Product::find($order->product_id);
        $order->qty = $order->qty - $request->input('qty');
        $product->inv = $product->inv + $order->qty;
        $product->save();
        $order->save();
            return redirect('/myorders');
    
        }  
        
    }

and this is the routes file

Route::get('/myorders', '[email protected]');
Route::get('/add_order', '[email protected]');
Route::get('/add_order/{id}', '[email protected]');
Route::get('/update_order', '[email protected]');
Route::get('/update_order/{id}', '[email protected]');
Route::get('/delete_order', '[email protected]');
Route::get('/delete_order/{id}', '[email protected]');

and this is my view, I am using it with

<div class="klaviyo_modal" id="update_order_qty" style="display:none;">
    <div class="klaviyo_inner">
        <a href="Cancel" class="klaviyo_close_modal klaviyo_header_close">×</a>
            <form method="GET" action="/update_order/{{ $order['id'] }}" enctype="multipart/form-data">
                {{ csrf_field() }}
                    <p class="klaviyo_header">Please update quantity as you need, then order it.</p>
                        <div class="klaviyo_fieldset">
                            <div class="{{ $errors->has('qty') ? ' has-error' : '' }}">
                                <label for="qty" style="display:block;text-align:center;margin-bottom:25px">Ordered New Quantity will be ADDED to your CURRENT Order Quantity</label>
                                    <input type="number" id="qty" class="qty" name="qty" style="display:block;margin:auto" required="required" placeholder="CURRENT Quantity">
                                    @if ($errors->has('qty'))
                                    <span class="help-block">
                                         <strong style="display:block;text-align:center">{{ $errors->first('qty') }}</strong>
                                    </span>
                                    @endif
                            </div>
                        </div>
          <div class="klaviyo_fine_print"></div>
              <div class="klaviyo_form_actions">
                 <button type="submit" class="klaviyo_submit_button">
                        <span>Update Order Quantity Now</span>
                 </button>
              </div>



            <!-- <span class="help-block">
                  <div class="success_message" style="display: block; text-align:center">Order Updated Successfully</div><br>
            </span>   
            <span class="help-block">  
                  <strong class="error_message" style="display: block; text-align:center">Sorry, Product Out of Stock, Try again later</strong>
            </span> -->        



            </form>
    </div>
</div>
06 Oct
2 months ago

AndreLan left a reply on When I Press The Buy Button I Get This Error

@taylormaguire Do you mean this ??

Route::get('/add_order/{id}', '[email protected]');

AndreLan left a reply on When I Press The Buy Button I Get This Error

It gave me this Request {#40 ▼ #json: null #convertedFiles: null #userResolver: Closure {#124 ▶} #routeResolver: Closure {#148 ▶} +attributes: ParameterBag {#42 ▶} +request: ParameterBag {#48 ▶} +query: ParameterBag {#48 ▶} +server: ServerBag {#45 ▶} +files: FileBag {#44 ▶} +cookies: ParameterBag {#43 ▶} +headers: HeaderBag {#46 ▶} #content: null #languages: null #charsets: null #encodings: null #acceptableContentTypes: null #pathInfo: "/add_order/2" #requestUri: "/add_order/2" #baseUrl: "" #basePath: null #method: "GET" #format: null #session: Store {#166 ▶} #locale: null #defaultLocale: "en" }

AndreLan left a reply on When I Press The Buy Button I Get This Error

@taylormaguire

the same error

QueryException in Connection.php line 729: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'qty' cannot be null (SQL: insert into orders (user_id, product_id, qty, updated_at, created_at) values (2, 2, , 2018-10-07 01:20:19, 2018-10-07 01:20:19))

AndreLan left a reply on When I Press The Buy Button I Get This Error

@mattsplat I got this :D

Request {#40 ▼ #json: null #convertedFiles: null #userResolver: Closure {#124 ▶} #routeResolver: Closure {#148 ▶} +attributes: ParameterBag {#42 ▶} +request: ParameterBag {#48 ▶} +query: ParameterBag {#48 ▶} +server: ServerBag {#45 ▶} +files: FileBag {#44 ▶} +cookies: ParameterBag {#43 ▶} +headers: HeaderBag {#46 ▶} #content: null #languages: null #charsets: null #encodings: null #acceptableContentTypes: null #pathInfo: "/add_order/2" #requestUri: "/add_order/2" #baseUrl: "" #basePath: null #method: "GET" #format: null #session: Store {#166 ▶} #locale: null #defaultLocale: "en" }

AndreLan left a reply on When I Press The Buy Button I Get This Error

@taylormaguire

No, it is just for the js , and to get sure I did what you said and changed it to qty and the same error

AndreLan left a reply on When I Press The Buy Button I Get This Error

I changed again to avoid misunderstanding :D

AndreLan left a reply on When I Press The Buy Button I Get This Error

No. It is called qty, I just changed it in the error message to define that it is an integer

AndreLan started a new conversation When I Press The Buy Button I Get This Error

When I press the buy button I get this error

QueryException in Connection.php line 729: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'quantity' cannot be null (SQL: insert into orders (user_id, product_id, quantity, updated_at, created_at) values (3, 1, , 2018-10-06 20:44:27, 2018-10-06 20:44:27))

first of all, I'm a beginner so I'm still learning and I do not know if some of this is correct, all I want is when I press the buy button it will display the form and I will type the quantity then submit and my quantity will increase and the products inventory will decrease and if I deleted my order, The products will increase again (I did this and I think it will work) and the user can update his quantity and if someone ordered something the seller cannot delete it, only update his inventory as same as the buy button way and the form, and if the users ordered all products it will display (out of stock) with a dead link button, I am training, It is not homework and I do not know how to write all functions..

this is the Buy button

<li><span><a href="/add_order/{{ $product['id'] }}">Buy</a></span></li>

which should pop up the next form when I press it,

this is my form code for the buy button

<form method="POST" action="/add_order/{{ $product['id'] }}" class="klaviyo_subscription_form" enctype="multipart/form-data">
                {{ csrf_field() }}
                    <input type="hidden" name="g" value="LIST_ID">
                        <div class="klaviyo_fieldset">
                            <p class="klaviyo_header">Please define quantity you need, then order it.</p>
                        </div>
                            <div class="klaviyo_fieldset">
                                <div class="klaviyo_field_group{{ $errors->has('qty') ? ' has-error' : '' }}">
                                    <label for="k_id_modal_$email" style="display: block; text-align:center">Quantity</label>
                                        <input type="number" id="k_id_modal_$email" name="qty" style="display: block; margin:auto">
                                        @if ($errors->has('qty'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('qty') }}</strong>
                                        </span>
                                        @endif
                                </div>
                            </div>

                                <div class="klaviyo_fine_print"></div>
                                    <div class="klaviyo_form_actions">
                                        <button type="submit" class="klaviyo_submit_button">
                                            <span>Order Now</span>
                                        </button>
                                    </div>
                                <div class="klaviyo_below_submit" ></div>
            </form>

and this is the OrderController functions

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Order;
use App\Product;
use Auth;
use App\User;
use App\Details;

class OrderController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth');
    }

    public function myorders()
    {
        $orders = Order::where('user_id','=',Auth::user()->id)->orderBy('id','desc')->get();
        return view('order.myorders',compact('products','orders','users'));
    }

    public function store(Request $request, $id)
        {
            $product = Product::find($id);
            $order = new Order();
            $order->user_id = Auth::user()->id;
            $order->product_id = $id;
            $order->qty = $request->get('qty');
            $product->inv = $product->inv - $order->qty;
            $order->save();
            $product->save();
            return redirect('/');
     
        }
       
    
    
        public function buy($id)
        {
            $product = Product::where('order_id','=',$id)->get();
            return view('order.buy',compact('order','product','user'));    
        
        return redirect('/buy');
        }

public function destroy($id)
    {
        $order = Order::find($id);
        $product= Product::find($order->product_id);
        $product->inv = $product->inv + 1;
        $product->save();
        $order->delete();
        return redirect('/myorders');

    }

thanks for reading :D