sunilbfcj

Member Since 1 Year Ago

Experience Points
1,320
Total
Experience

3,680 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
1
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.

  • Community Pillar

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

Level 1
1,320 XP
Mar
06
1 month ago
Activity icon

Replied to Count Function Return More Than String Length!

I also tried

foreach($header as $key){
  //echo 'key name: '.$key.'<br>';
  //print_r(unpack("C*", $key)).'<br>';
  foreach (count_chars($key, 1) as $i => $val) {
     echo "There were $val instance(s) of \"" , chr($i) , "\" in the string.\n";
  }
}

and result is: -

There were 1 instance(s) of "_" in the string.
There were 1 instance(s) of "a" in the string.
There were 1 instance(s) of "e" in the string.
There were 1 instance(s) of "f" in the string.
There were 1 instance(s) of "i" in the string.
There were 1 instance(s) of "m" in the string.
There were 1 instance(s) of "n" in the string.
There were 1 instance(s) of "r" in the string.
There were 1 instance(s) of "s" in the string.
There were 1 instance(s) of "t" in the string.
There were 1 instance(s) of "�" in the string.
There were 1 instance(s) of "�" in the string.
There were 1 instance(s) of "�" in the string.

What is this:-

There were 1 instance(s) of "�" in the string.
There were 1 instance(s) of "�" in the string.
There were 1 instance(s) of "�" in the string.

how can I resolve it !!!!

Activity icon

Started a new Conversation Count Function Return More Than String Length!

I am importing csv file and extracted header

$data = array_map('str_getcsv', file($request->input('file')));
$header = $data[0];

the value of $header[0] is 'first_name' but when i counted it with count method its length was 13 that should be 10. same as middle_name and last_name values producing same result and other is ok.

to find out hidden character I tried:

foreach($header as $key){
       echo 'key name: '.$key.'<br>';
       print_r(unpack("C*", $key)).'<br>';
}

and the output is:- please focus on last 3 values of each array is same.

Please tell me how i can solve it. Thanks

key name: first_name
Array
(
    [1] => 239
    [2] => 187
    [3] => 191
    [4] => 102
    [5] => 105
    [6] => 114
    [7] => 115
    [8] => 116
    [9] => 95
    [10] => 110
    [11] => 97
    [12] => 109
    [13] => 101
)
key name: middle_name
Array
(
    [1] => 109
    [2] => 105
    [3] => 100
    [4] => 100
    [5] => 108
    [6] => 101
    [7] => 95
    [8] => 110
    [9] => 97
    [10] => 109
    [11] => 101
)
key name: last_name
Array
(
    [1] => 108
    [2] => 97
    [3] => 115
    [4] => 116
    [5] => 95
    [6] => 110
    [7] => 97
    [8] => 109
    [9] => 101
)
key name: phone
Array
(
    [1] => 112
    [2] => 104
    [3] => 111
    [4] => 110
    [5] => 101
)
key name: email
Array
(
    [1] => 101
    [2] => 109
    [3] => 97
    [4] => 105
    [5] => 108
)
key name: cluster_head
Array
(
    [1] => 99
    [2] => 108
    [3] => 117
    [4] => 115
    [5] => 116
    [6] => 101
    [7] => 114
    [8] => 95
    [9] => 104
    [10] => 101
    [11] => 97
    [12] => 100
)
key name: team_leader
Array
(
    [1] => 116
    [2] => 101
    [3] => 97
    [4] => 109
    [5] => 95
    [6] => 108
    [7] => 101
    [8] => 97
    [9] => 100
    [10] => 101
    [11] => 114
)
key name: ctc_Lacs
Array
(
    [1] => 99
    [2] => 116
    [3] => 99
    [4] => 95
    [5] => 76
    [6] => 97
    [7] => 99
    [8] => 115
)
key name: remarks
Array
(
    [1] => 114
    [2] => 101
    [3] => 109
    [4] => 97
    [5] => 114
    [6] => 107
    [7] => 115
)
key name: bank
Array
(
    [1] => 98
    [2] => 97
    [3] => 110
    [4] => 107
)
key name: skill
Array
(
    [1] => 115
    [2] => 107
    [3] => 105
    [4] => 108
    [5] => 108
)
key name: vertical
Array
(
    [1] => 118
    [2] => 101
    [3] => 114
    [4] => 116
    [5] => 105
    [6] => 99
    [7] => 97
    [8] => 108
)
key name: designation
Array
(
    [1] => 100
    [2] => 101
    [3] => 115
    [4] => 105
    [5] => 103
    [6] => 110
    [7] => 97
    [8] => 116
    [9] => 105
    [10] => 111
    [11] => 110
)
key name: grade
Array
(
    [1] => 103
    [2] => 114
    [3] => 97
    [4] => 100
    [5] => 101
)
key name: branch
Array
(
    [1] => 98
    [2] => 114
    [3] => 97
    [4] => 110
    [5] => 99
    [6] => 104
)
key name: state
Array
(
    [1] => 115
    [2] => 116
    [3] => 97
    [4] => 116
    [5] => 101
)
key name: district
Array
(
    [1] => 100
    [2] => 105
    [3] => 115
    [4] => 116
    [5] => 114
    [6] => 105
    [7] => 99
    [8] => 116
)
key name: city
Array
(
    [1] => 99
    [2] => 105
    [3] => 116
    [4] => 121
)
Feb
03
2 months ago
Activity icon

Awarded Best Reply on My Database Connection Setup Successfully But When I Try To Migrate It Shows Error:-

Now the problem is resolved

I was using '#' in my password but # represents comments in the .env file and half of my password was commented

DB_PASSWORD=FULL#PASSWORD   // here password is a comment 

This means that my database credentials were incorrect

Activity icon

Replied to My Database Connection Setup Successfully But When I Try To Migrate It Shows Error:-

Now the problem is resolved

I was using '#' in my password but # represents comments in the .env file and half of my password was commented

DB_PASSWORD=FULL#PASSWORD   // here password is a comment 

This means that my database credentials were incorrect

Feb
02
2 months ago
Activity icon

Replied to My Database Connection Setup Successfully But When I Try To Migrate It Shows Error:-

Hi @tray2

Thanks for the reply, I am using correct credentials but there is something wrong, I don't know what is it?

I am uploading it on AWS ec2 instance

Please look at 42 Seconds video https://drive.google.com/file/d/1tg0k6fdffDI_p_-zM-Froc7bfziiafT4/view?usp=sharing

Feb
01
2 months ago
Activity icon

Started a new Conversation My Database Connection Setup Successfully But When I Try To Migrate It Shows Error:-

I tried the way to check to connection https://laracasts.com/discuss/channels/laravel/easy-way-to-check-if-laravel-app-has-connection-with-existing-mysql-db

but at the time of migration it produce error

Illuminate\Database\QueryException 

  SQLSTATE[HY000] [1045] Access denied for user 'panditdev'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = panditji and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
    674▕         // If an exception occurs when attempting to run a query, we'll format the error
    675▕         // message to include the bindings with SQL, which will make this exception a
    676▕         // lot more helpful to the developer instead of just the database's errors.
    677▕         catch (Exception $e) {
  ➜ 678▕             throw new QueryException(
    679▕                 $query, $this->prepareBindings($bindings), $e
    680▕             );
    681▕         }
    682▕ 

      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Please help me thanks in advance.

Jan
21
2 months ago
Activity icon

Replied to Dynamic Routes Laravel

Route::get('buy/{where}/{places?}', '[email protected]');

Search Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SearchController extends Controller
{
    /**
     * Handle the incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function places(Request $request, $where, $places = null)
    {
        if(is_null($places)){
		// code
	}
        else{
		// code
	}
    }
}
Jan
20
2 months ago
Activity icon

Started a new Conversation I Have More Than One Controller With Same Name In Different Folder How I Can Implement Those?

// For admin
use App\Http\Controllers\Manage\Administrator\OrderController;
Route::get('my-orders/by/{type}/{val}', [OrderController::class, 'by']);


// For seller
use App\Http\Controllers\Manage\Vendor\OrderController;
Route::get('my-orders/by/{type}/{val}', 'Manage\Vendor\[email protected]'); // How can I write it?

Thanks

Jan
19
2 months ago
Activity icon

Replied to Is It Possible To Switch From Fortify To Breeze

Most of the time we waste our time and power to find alternatives but, we already have a solution and besides that we are looking for something else ...

I am tired now in hopes of becoming smart.

As I can see you are still waiting for an option, but I want to say don't waste your time and do as you can.

Thank you with love

Activity icon

Replied to How Can I Use Condition On Model?

@martinbean Thanks for the reply :)

I know its options. As you can see I am a beginner but I always try to write code flexibly in different ways. I always try to play with the code and most of the time I fail.

Most of the time when I encounter bugs and unfortunately I do not get more than 10 (solution) answers on each of my questions.

Thanks everyone for the reply. May god bless you :))

Activity icon

Replied to How Can I Use Condition On Model?

or when I used:-

Product::search($request->keyword)->withoutGlobalScopes()->get();

than output was:- Method Laravel\Scout\Builder::withoutGlobalScopes does not exist.

Activity icon

Replied to How Can I Use Condition On Model?

Product::withoutGlobalScopes()->search($request->keyword)->get();

the output is :- Call to undefined method Illuminate\Database\Eloquent\Builder::search() ; I had already tried it!

Activity icon

Started a new Conversation How Can I Use Condition On Model?

I have a product model. In this model, I used a global scope for filtering seller but when I tried to import or search records by using laravel scout it fails. Take a look at product model:-

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Scopes\ProductScope;
use Carbon\Carbon;
use Laravel\Scout\Searchable;

class Product extends Model
{
    use SoftDeletes, Searchable;

    protected static function booted()
    {
        static::addGlobalScope(new ProductScope);
    }

}

Global scope:-

<?php

namespace App\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Auth;

class ProductScope implements Scope
{
    /**
     * Apply the scope to a given Eloquent query builder.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $builder
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @return void
     */
    public function apply(Builder $builder, Model $model)
    {
        $builder->where(['store_id' => Auth::user()->id, 'type' => Auth::user()->role])->whereNotNull('parent_id')->orderBy('id','desc');
    }
}

now my query is

Product::search($request->keywords)->get();

it only finds the records related with current user.

now I want to add a condition in model something like this:-

protected static function booted()
{
	if(condition)  // search method used or not ??? if not the proceed with global scope else not
        	static::addGlobalScope(new ProductScope);
}

If it is possible help me or suggest another possible solution. Thanks to all... :))

Dec
22
3 months ago
Activity icon

Replied to Is Full Text Search Possible With Some Conditions?

I tried before.

Please look at the error:- https://ibb.co/TgWz3FQ

Activity icon

Replied to Save A Nested Array In Database


        $prepared = collect($data['data'])->map(function($item) use ($timestamp) {
            $item['created_at'] = $timestamp;
            $item['updated_at'] = $timestamp;
	    Employee::insert($item); // $item must be an array
            return $item;
        });
Activity icon

Replied to Get The Latest Reviewed Games

$user = DB::table('users')->latest()->first();

Activity icon

Replied to Is Full Text Search Possible With Some Conditions?

@james_bhatta Thanks for your reply

Ok let's say I'm logged in and you think the error has been fixed ??

But what do you think? How can I import a model?

php artisan scout:import App\Models\Product
Activity icon

Replied to Is Full Text Search Possible With Some Conditions?

Error while importing for indexes

php artisan scout:import App\Models\Product
Activity icon

Replied to Is Full Text Search Possible With Some Conditions?

Thanks for your reply :) Yes, it is working nice :)

But, When I tried to import it gives an error! "Trying to get property 'id' of non-object".

So I removed it.

my code:-

<?php

namespace App\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Auth;

class ProductScope implements Scope
{
    /**
     * Apply the scope to a given Eloquent query builder.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $builder
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @return void
     */
    public function apply(Builder $builder, Model $model)
    {
        $builder->where('type', Auth::user()->id)->whereNull('parent_id')->orderBy('id','desc');
    }
}

Now I am using:-

$builder->whereNull('parent_id')->orderBy('id','desc');
Activity icon

Started a new Conversation Is Full Text Search Possible With Some Conditions?

I am using "laravel scout" and "tntsearch scout driver" for "indexing".

I have a product table:-

| id | title            | price   | type        | parent_id | store_id |
------------------------------------------------------------------------
| 1  | Paneer 65        | 120     | food        | null      | null     |
| 2  | Samsung galaxy   | 13500   | Smartphones | null	    | null     |
| 3  |                  | 110     | food        | 1         | 10       |
  1. This table where store_id is null is created by the administrator. These products can be imported by various stores according to their role and edit the price.
  2. A store with ID 10 imports a product with ID 1 (Paneer 65) and defines the value (110) for the product.

Note: If the store's role is food, it can only import food-type products. This rule is applied to each type of shop.

But, as we know all products are searchable according to "full text index". When I tried to find a product, the restaurant found unwanted products like "Samsung Galaxy" to import.

This problem also persists for other shops.

Now, how can I solve this?

I tried to write a conditional statement but it does not work!

$result = \App\Models\Product::search($keyword)->where('type', Auth::user()->role)->get();

Please solve it Thanks in advance

Nov
23
4 months ago
Activity icon

Started a new Conversation How Can I Implement WithoutGlobalScopes With Route Model Binding

public function update(Request $request, Order $order)
{
	// My code...
}

Thanks in advance.

Nov
01
5 months ago
Activity icon

Replied to Laravel 8 Routes Broken

It is declared two times please remove one of them

Route::get('/home', '[email protected]')->name('home');
Activity icon

Replied to Laravel 8 Routes Broken

In such a situation, I always put my path on the top of all the routes.

Activity icon

Started a new Conversation How Can I Log The User In My Subdomain When The User Logs Into The Main Website

I have a separate subdomain for the seller https://business.scarenot.com

I want the vendor to go to the dashboard without login to the above domain upon logging into the main domain.

Activity icon

Replied to How To UpdateOrCreate With Conditional Clauses

This is right :)

It is working well. Now my code is short than before. Thanks for your help.

Oct
31
5 months ago
Activity icon

Started a new Conversation How To UpdateOrCreate With Conditional Clauses

I am logging in with Google and Facebook. If it is joining for the first time then it should fill a random password otherwise, it will not update the current password.

I know it is even more possible if there is a condition, but I would like to know if it is possible with "conditional clause"?

$newUser = User::updateOrCreate(
    [
        'email' => $user->email
    ],
    [
        'name' => $user->name,
        'google_id'=> $user->id,
        'password' => encrypt($user->email.''.$user->id),	// if already exists don't update or update with current password
        'email_verified_at' => Carbon::now()->toDateTimeString(),
    ]
);
Oct
27
5 months 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
5 months ago
Activity icon

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

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

Oct
17
6 months 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);