sunilbfcj

sunilbfcj

Member Since 1 Year Ago

Experience Points
520
Total
Experience

4,480 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 Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 1
520 XP
Oct
27
4 days ago
Activity icon

Replied to Redirect After Login According To User Role Laravel Fortify

That means I need to install jetstream!

Activity icon

Replied to Redirect After Login According To User Role Laravel Fortify

in my web.php

Route::group(['middleware' => ['sellers', 'verified'], 'verify' => true], function ()
{
    Route::get('/dashboard', function(){
        return view('dashboard');
    })->name('dashboard');

    Route::get('profile', function(){
        return view('users/profile');
    })->name('profile');

    Route::post('product/get/variants', [ProductController::class, 'getVariants']);

    Route::resources([
        'orders' => OrderController::class,
        'product' => ProductController::class,
    ]);

});
Activity icon

Replied to Redirect After Login According To User Role Laravel Fortify

protected $routeMiddleware = [
        'sellers' => \App\Http\Middleware\Sellers::class,
];

in app\Http\Kernel.php

Activity icon

Started a new Conversation Redirect After Login According To User Role Laravel Fortify

I want to redirect on different URLs after login. I am using laravel fortify. I am always redirecting on URL which is defined in config\fortify.php

'home' => RouteServiceProvider::HOME,

// or

'home' => '/dashboard'

but it must be a conditional redirect. I tried to redirect by using a middleware but not redirecting.

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class Sellers
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!Auth::check()) {
            return redirect()->route('login');
        }
        elseif(in_array(Auth::user()->role, ['grocery', 'restaurant', 'pharmacy', 'delivery', 'vegetables'])) {
            return redirect('dashboard');
        }
        return $next($request);
    }
}

Finally, I tried according to laravel official documentation but also failed. https://laravel.com/docs/8.x/authentication#redirecting-unauthenticated-users

Please help me, thanks in advance.

Oct
18
1 week ago
Activity icon

Replied to Laravel Session::get('key') Always Returns Null

Thank you, for your valuable time. it's working now.

Oct
17
2 weeks ago
Activity icon

Started a new Conversation Laravel Session::get('key') Always Returns Null

I am adding product in cart using session but when I refresh page session return null for the key.

$product = Product::where('slug', $request->slug)->where('status', 'published')->first();

$cart = Session::has('cartdata') ? json_decode(Session::get('cartdata')) : [];
          //dd($cart);
          if(!isset($cart[$product->id])){
            $cart[$product->id][] = [
              'attributes' => $product->type=='variable' ? json_encode($request->attribute) : null,
              'quantity' => $request->quantity,
              'cart_type' => $request->addToWishlist ? 'wishlist' : 'cart'
            ];
          }
          else{
            $found = 1;
            $attribute = $product->type=='variable' ? json_encode($request->attribute) : null;
            foreach($cart[$product->id] as $key => $val){
              //echo $cart[$product->id][$key]['attributes'].' / '.$attribute;
              if($cart[$product->id][$key]['attributes']==$attribute){
                $cart[$product->id][$key]['quantity'] = $request->quantity;
                $cart[$product->id][$key]['cart_type'] = $request->addToWishlist ? 'wishlist' : 'cart';
                $found = 0;
              }
            }
            if($found){
              $cart[$product->id][] = [
                'attributes' => $product->type=='variable' ? json_encode($request->attribute) : null,
                'quantity' => $request->quantity,
                'cart_type' => $request->addToWishlist ? 'wishlist' : 'cart'
              ];
            }
          }
          if(count($cart)){
            $request->session()->put('cartdata', json_encode($cart));
          }
          dd($cart);
Aug
15
2 months ago
Activity icon

Replied to Call To Undefined Method StdClass::notify()

@sinnbeck Thanks for the reply. it work.

Activity icon

Started a new Conversation Call To Undefined Method StdClass::notify()

I want to send email to multiple users but an error occurs Call to undefined method stdClass::notify()

// My query
$stores = DB::table('users')
->select('id', 'email', 'name', $raw)
->where('id','!=', Auth::user()->id)
->where('role', $order->type)
->where('pincode', Auth::user()->pincode)
->where('city', Auth::user()->city)
->addSelect($raw)
->orderBy('distance', 'ASC')
->having('distance', '<=', 3)
->limit(10)
->get();

// Sending email to the retrieved stores
foreach($stores as $user){
     $user->notify(new OrderCreatedMessage($data));
}

When I used User::all(), find() and first() works correctly but not the above query.

Aug
12
2 months ago
Activity icon

Replied to SQLSTATE[42000]: Syntax Error Or Access Violation: 1071 Specified Key Was Too Long; Max Key Length Is 767 Bytes (SQL: Alter Table `products` Add Unique `products_slug_unique`(`slug`))

I defined 500 characters for the product title which will be converted into a slug.

I never used UUID is it a better option to use rather than a slug?

Activity icon

Replied to SQLSTATE[42000]: Syntax Error Or Access Violation: 1071 Specified Key Was Too Long; Max Key Length Is 767 Bytes (SQL: Alter Table `products` Add Unique `products_slug_unique`(`slug`))

Thanks for your reply

As we know without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows and it causes poor performance. Is any other option available here to find a product by slug?

If any solution please tell me. Thanks

Activity icon

Started a new Conversation SQLSTATE[42000]: Syntax Error Or Access Violation: 1071 Specified Key Was Too Long; Max Key Length Is 767 Bytes (SQL: Alter Table `products` Add Unique `products_slug_unique`(`slug`))

I want to make slug as a unique index but it failed: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table products add unique products_slug_unique(slug))

$table->string('slug', 1000)->unique();

But, it was succeeded when I tried it

$table->string('slug', 1000);
May
14
5 months ago
Activity icon

Replied to Argument 2 Passed To Illuminate\Routing\UrlGenerator::__construct() Must Be An Instance Of Illuminate\Htt P\Request, Null Given, Called In /root/Downloads/locate/vendor/laravel/framework/src/Illuminate/Routing/R OutingServiceProvider.php On Line 6

I was using url() method inside services.php

'google' => [
        'client_id' => '1046770465850-klphk4fk6lfaalct38hq1fosbou4nchj.apps.googleusercontent.com',
        'client_secret' => 'yQQ_82Iv_JVnJTV8VFdkAj5n',
        'redirect' => url('/').'/auth/google/callback',
    ],

    'facebook' => [
        'client_id' => '198553204622369',
        'client_secret' => '737be72267ff6dccb518b063645a7808',
        'redirect' => url('/').'/auth/facebook/callback',
    ],

    'twitter' => [
        'client_id' => 't14CCCqKivvJCy39CYJESR9XS',
        'client_secret' => 'uN1OFUKjvRWxyWXmS5Spaa2X2axju31i3KNRR3Vz28NYKX2Tmj',
        'redirect' => url('/').'/auth/twitter/callback',
    ],
Activity icon

Started a new Conversation Argument 2 Passed To Illuminate\Routing\UrlGenerator::__construct() Must Be An Instance Of Illuminate\Htt P\Request, Null Given, Called In /root/Downloads/locate/vendor/laravel/framework/src/Illuminate/Routing/R OutingServiceProvider.php On Line 6

Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Htt  
  p\Request, null given, called in /root/Downloads/locate/vendor/laravel/framework/src/Illuminate/Routing/R  
  outingServiceProvider.php on line 65

Thanks in advance!

Apr
30
6 months ago
Activity icon

Awarded Best Reply on Required If Array Of Checkbox Is Checked

my rule for validation should be:

$validate['variant_manage_stock.*'] = ['sometimes', 'accepted'];
$validate['variant_stock_quantity.*'] = ['nullable', 'numeric', 'min:2'];
$validate['variant_allow_backorder.*'] = ['required', 'in:no,notify,yes'];
$validate['variant_stock_threshold.*'] = ['nullable', 'numeric', 'min:1', 'lt:variant_stock_quantity.*'];

Thanks to all laracasters for their valuable time.

Activity icon

Replied to Required If Array Of Checkbox Is Checked

my rule for validation should be:

$validate['variant_manage_stock.*'] = ['sometimes', 'accepted'];
$validate['variant_stock_quantity.*'] = ['nullable', 'numeric', 'min:2'];
$validate['variant_allow_backorder.*'] = ['required', 'in:no,notify,yes'];
$validate['variant_stock_threshold.*'] = ['nullable', 'numeric', 'min:1', 'lt:variant_stock_quantity.*'];

Thanks to all laracasters for their valuable time.

Activity icon

Replied to Required If Array Of Checkbox Is Checked

Thanks for the reply.

	
_token	"3AtIxxNERtxJLigJhKIagpYZpHIJKP0szZFvJgEC"
product_title	null
product_description	null
product_type	"variable"
regular_price	null
sale_price	null
product_url	null
button_text	"Buy now"
product_sku	null
stock_quantity	null
allow_backorder	"no"
stock_threshold	"2"
product_weight	null
product_length	null
product_width	null
product_height	null
shipping_class	"2"
tax_class	"1"
add_new_attribute	null
attribute_name	
0	"size"
1	"color"
attribute_value	
size	
0	"L"
1	"XL"
2	"XXL"
color	
0	"Black"
1	"Blue"
add-attribute_value	null
variant_regular_price	
0	"500"
1	null
2	null
3	null
4	null
5	"600"
variant_sale_price	
0	"300"
1	null
2	null
3	null
4	null
5	"500"
variant_product_sku	
0	null
1	null
2	null
3	null
4	null
5	null
variant_stock_quantity	
0	null
1	null
2	null
3	null
4	null
5	null
variant_allow_backorder	
0	"no"
1	"no"
2	"no"
3	"no"
4	"no"
5	"no"
variant_stock_threshold	
0	null
1	null
2	null
3	null
4	null
5	null
variant_product_weight	
0	null
1	null
2	null
3	null
4	null
5	null
variant_product_length	
0	null
1	null
2	null
3	null
4	null
5	null
variant_product_width	
0	null
1	null
2	null
3	null
4	null
5	null
variant_product_height	
0	null
1	null
2	null
3	null
4	null
5	null
variant_shipping_class	
0	null
1	null
2	null
3	null
4	null
5	null
variant_tax_class	
0	null
1	null
2	null
3	null
4	null
5	null
product_short_description	null
product_status	"public"

my html code

<div class="form-group col-12">
    <label class="checkbox d-block pl-3" style="padding-top: 2px;"><input type="checkbox" name="variant_manage_stock[${index}]" value="1" class="selectable variant_manage_stock"><span class="checkmark"></span>Manage Stock (Enable stock management at product level)</label>
</div>

<div class="form-group col-12 col-md-4 type-stock">
    <label>Stock quantity <i class="fas fa-question-circle" data-toggle="tooltip" data-placement="bottom" title="Stock quntity. If this is a variable product this value will be used to control stock for all variations, unless you define stock at variation level."></i></label>
    <input type="number" name="variant_stock_quantity[${index}]" class="form-control" value="">

    <span class="invalid-feedback" role="alert">
        <strong></strong>
    </span>
</div>

<div class="form-group col-12 col-md-4 type-stock">
    <label>Allow Backorder <i class="fas fa-question-circle" data-toggle="tooltip" data-placement="bottom" title="If managing stock, this controls whether or not backorders are allowed. If enabled, stock quantity can go below 0."></i></label>
    <select name="variant_allow_backorder[${index}]" class="form-control">
        <option value="no">Do not allow</option>
        <option value="notify">Allow, but notify customer</option>
        <option value="yes">Allow</option>
    </select>

    <span class="invalid-feedback" role="alert">
        <strong></strong>
    </span>
</div>

<div class="form-group col-12 col-md-4 type-stock">
    <label>Low stock threshold <i class="fas fa-question-circle" data-toggle="tooltip" data-placement="bottom" title="When product stock reaches this amount you will be notified by email."></i></label>
    <input type="text" name="variant_stock_threshold[${index}]" class="form-control" value="">

    <span class="invalid-feedback" role="alert">
        <strong></strong>
    </span>
</div>

Now I want to validate 'variant_stock_threshold' field it should be required and less than if 'variant_stock_quantity' is not null or till it not fullfill.

Activity icon

Started a new Conversation Required If Array Of Checkbox Is Checked

I am creating variants for products. For each variant, if manage stock checkbox is checked then the user must enter the stock but at the time of validation stock quantity asked for each variant.

$validate['variant_manage_stock.*'] = ['sometimes', 'accepted'];
$validate['variant_stock_quantity.*'] = ['required_if:variant_manage_stock.*,1', 'numeric'];
$validate['variant_allow_backorder.*'] = ['required', 'in:no,notify,yes'];
$validate['variant_stock_threshold.*'] = ['required_if:variant_manage_stock.*,1', 'numeric', 'min:1', 'lt:variant_stock_quantity.*'];

I also tried.

$validate['variant_manage_stock.*'] = ['sometimes', 'accepted'];
$validate['variant_stock_quantity.*'] = ['required_with:variant_manage_stock.*,on', 'numeric'];
$validate['variant_allow_backorder.*'] = ['required', 'in:no,notify,yes'];
$validate['variant_stock_threshold.*'] = ['required_with:variant_manage_stock.*,on', 'numeric', 'min:1', 'lt:variant_stock_quantity.*'];

validation errors:- The variant_stock_quantity.0 must be a number.

The variant_stock_quantity.1 must be a number. The variant_stock_quantity.2 must be a number. The variant_stock_quantity.3 must be a number. The variant_stock_quantity.4 must be a number. The variant_stock_quantity.5 must be a number. The variant_stock_threshold.0 must be less than variant_stock_quantity.0. The variant_stock_threshold.1 must be less than variant_stock_quantity.1. The variant_stock_threshold.2 must be less than variant_stock_quantity.2. The variant_stock_threshold.3 must be less than variant_stock_quantity.3. The variant_stock_threshold.4 must be less than variant_stock_quantity.4. The variant_stock_threshold.5 must be less than variant_stock_quantity.5.