gorakhyadav

gorakhyadav

Member Since 1 Year Ago

Experience Points 2,290
Experience Level 1

2,710 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 2
Lessons
Completed
Best Reply Awards 3
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.

16 Mar
3 months ago

gorakhyadav left a reply on Why Using : Let Self = This?

Use $this to refer to the current object. Use self to refer to the current class. In other words, use $this->member for non-static members, use self::$member for static members.

Here is an example of correct usage of $this and self for non-static and static member variables:

   class X {
              private $non_static_member = 1;
              private static $static_member = 2;

       function __construct() {
                  echo $this->non_static_member . ' '
                  .self::$static_member;
        }
    }

          new X();

gorakhyadav left a reply on Remember_me Token Not Being Set

we always use remember me option in login page, that way user don't require to login everytime. So, we would like use remember me option in our login page then you can also do it simply, because laravel provide it's own functionality. But, many developer can't do it properly i mean remember me not working, but you can implement it right.

First you have to sure that remember_token field in our users table. if you haven't remember_token column then first add it in your users table or any table that you use as for auth.

Now you should have controller method this way:

Example:

     public function login(Request $request)
     {
       $this->validate($request, [
     'email' => 'required|email',
     'password' => 'required',
     ]);


     $remember_me = $request->has('remember_me') ? true : false; 


    if (auth()->attempt(['email' => $request->input('email'), 'password' => $request->input('password')], 
    $remember_me))
    {
    $user = auth()->user();
     dd($user);
    }else{
    return back()->with('error','your username and password are wrong.');
    }
    }

gorakhyadav left a reply on Remember_me Token Not Being Set

Laravel authentication offers remember me functionality out of the box.

In order to use it you need to do 2 things:

1- add remember_token column in your users table - this is where the token will be stored 2- pass true as a second parameter of Auth::attempt() to enable remember me behaviour If you do this, Laravel will generate a token that will be saved in users table and in a cookie. On subsequent requests, even if session cookie is not available, user will be authenticated automatically as long as remember-me cookie is there.

You can find more details and example in the docs:

       https://laravel.com/docs/5.1/authentication#remembering-users

gorakhyadav left a reply on How To Auto-Scale Queue System ?

Try with this

  https://medium.com/square-corner-blog/autoscaling-based-on-request-queuing-c4c0f57f860f

gorakhyadav left a reply on What Is Main Difference In Two Sesson Data Process ?

They are just different ways of accessing your application's session object. With laravel You can access application session

Using session facade as Session::

Using request's session method $request->session()

You can read on it here laravel docs for session. Hope it helps !

check with this

   https://laravel.com/docs/5.0/session#session-usage

gorakhyadav left a reply on Laravel Accessor Appends Not Working As Expected / Strange Behavior

@JAHELLER - what are you getting in $this->vendorDetails ?

gorakhyadav left a reply on Laravel Accessor Appends Not Working As Expected / Strange Behavior

public function getIsVendorAttribute($vendorDetails) { return (is_null($vendorDetails)) ? false : true; }

gorakhyadav left a reply on How To Sum Values Of Duplicate ID's

@M4MARTIE - I said show me you database table structure image which is you are trying to fetch data.

gorakhyadav left a reply on Get The 15th Of The Month With Carbon

If you are checking on the month of year you can use MONTH and YEAR functions.

      SELECT fieldName
      FROM yourtable
      WHERE Month(InterviewDate) = 1
      AND Year(InterviewDate) IN (2010, 2011, 2012);

      SELECT fieldName
      FROM yourtable
       WHERE Month(InterviewDate) IN (1, 2) // if there are particular months
      AND Year(InterviewDate) IN (2010, 2011, 2012);

gorakhyadav left a reply on Get The 15th Of The Month With Carbon

I do not understand that do you want .but This is example of sql query ,you can try with this.

    SELECT fieldName
    FROM tableName
    WHERE Date BETWEEN '2012-01-01' AND '2012-01-31'
    OR Date BETWEEN '2011-01-01' AND '2011-01-31'
    OR Date BETWEEN '2010-01-01' AND '2010-01-31'

gorakhyadav left a reply on How To Sum Values Of Duplicate ID's

@M4MARTIE - Please show me your table structure and your query and what you want

15 Mar
3 months ago

gorakhyadav left a reply on Load More Than One Environment File

Create your .env.rdate file next to .env file.

Put this to your AppServiceProvider boot method:

   $dotenv = new \Dotenv\Dotenv(base_path(),'.env.rdate');
  $dotenv->overload(); 

After you can use in your project: ENV('APP_RELEASE_DATE')

gorakhyadav left a reply on How To Fetch Data In Mail Template From Database.

You could do like this:

   $email = Input::get('email');
   $user = User::where('email', $email)->first();

   if($user){
  $new_password = str_random(8); //generates random string , eight character long

  $user->password = \Hash::make($new_password);
  $user->save();

  $data = [
             'name'          => $user->first_name,
             'new_password ' => $new_password 
  ];

  Mail::send('emails.password-reset', $data, function($m) use ($user){
     $m->to($user->email, '')->subject('Password Request');
  });
  }


 In email template: views\emails\password-reset.blade.php:

 Hello {!!$name!!},

 Your password has been changed, successfully.
 Your new password is:"{!!$new_password!!}" 
 Kindly, change your password later on.

gorakhyadav left a reply on What Is The Reason For Using Index() In Migration?

It means the database server will create, well, an 'index' on that column. It makes queries faster for that column - so usually you'd use it on your primary key for instance. But maybe you find out you're looking up users by their email address a lot so you might add an index to that too.

There is a small performance hit for the database server maintaining the index (it has to update the index when you write a record to the db) - so you usually use them only where needed.

gorakhyadav left a reply on How To Use Authentication Using Username Instead Of Email

You need is add a property in app/Http/AuthController.php:

  protected $username = 'username';

Open your Illuminate\Foundation\Auth\AuthenticatesUsers.php and ediit

   public function postLogin(Request $request)
   {
    $this->validate($request, [
        $this->loginUsername() => 'required', 'password' => 'required',
     ]);

And then let’s look into loginUsername() method.

  public function loginUsername()
   {
    return property_exists($this, 'username') ? $this->username : 'email';
    }

As you can see, it’s looking for a property $this->username, otherwise defaults it to ’email’.

gorakhyadav left a reply on Select Nearest Cities From Table

If you already have the latitude and longitudes in your database you might as well query them yourself. This is from an older project (so may not work or be the best method) where I'm doing something similar:

This is Example of query please use your query like this

   $cities = City::select(DB::raw('*, ( 6367 * acos( cos( radians('.$latitude.') ) * cos( radians( latitude ) ) * cos( 
   radians( longitude ) - radians('.$longitude.') ) + sin( radians('.$latitude.') ) * sin( radians( latitude ) ) ) ) AS 
   distance'))
   ->having('distance', '<', 25)
   ->orderBy('distance')
    ->get();

gorakhyadav left a reply on Uploading Different Types Of Files

Try with this.

   https://www.jotform.com/help/29-How-to-Change-the-Allowed-File-Types-in-the-Upload-Field

gorakhyadav left a reply on How To Sum Values Of Duplicate ID's

use groupBy and try something like this.

   $points = ActivityPoint::where('points', '$reports->points')groupBy('user_id')->sum('points');
14 Mar
3 months ago

gorakhyadav left a reply on Not Sure How To Get 3 Months

@NIKKI - did you use import Carbon ?

gorakhyadav left a reply on Not Sure How To Get 3 Months

did you use import Carbon ?

gorakhyadav left a reply on Not Sure How To Get 3 Months

Try with that.

         $from= Carbon::now()->startOfMonth()->subMonth(3);
         $to= Carbon::now()->startOfMonth(); 
         $three_months = Order::whereBetween('created_at', [$from, $to])->get();

gorakhyadav left a reply on Not Sure How To Get 3 Months

$from = now(); $to = $from->copy()->addMonths(3);

$three_months = Order::whereBetween('created_at', [$from, $to])->get();

gorakhyadav left a reply on Export Collection With Laravel Excel

Try with this

  https://laraveldaily.com/laravel-excel-3-0-export-custom-array-excel/

gorakhyadav left a reply on How To Add " - " If Word Is Bigger Than 20 Characters.

Try something like this

   if (strlen($text)>20) {
   echo "more than 20";
    }
    else {
    echo "exactly text";
     }

gorakhyadav left a reply on Get Pagination For Full MySql And DB::select Query

$key = ' test word';

    $q = DB::select(' SELECT * , MATCH(col 1,col 2) AGAINST ("'.$key.'" IN BOOLEAN MODE) AS score FROM test 
    WHERE MATCH(col 1,col 2) AGAINST ("'.$key.'" IN BOOLEAN MODE)')->paginate(100);
13 Mar
3 months ago

gorakhyadav left a reply on Not Working Php Artisan Serve Command?

what error are you getting. can you show ?

gorakhyadav left a reply on How Can I Make A Data Available To All Views

Try Something like this

   return view('products.cart',[
    'data1'=>$data1,
         'data2'=>$data2,
       ]);
12 Mar
3 months ago

gorakhyadav left a reply on Best Practices: Vue.js -> Laravel AJAX API Resources

Try with this

 https://blog.pusher.com/web-application-laravel-vue-part-5/

gorakhyadav left a reply on Error Saving Date Format (d/m/Y) To (Y-m-d)

You can also use Add the $casts in the model, so you will solve the problem.

  protected $casts =[
  'birthday'=> 'date:Y-m-d'
  ];

gorakhyadav left a reply on Error Saving Date Format (d/m/Y) To (Y-m-d)

Try something like this. Date::make('Birthday')->resolveUsing(function ($date) { return $date->format('Y-m-d'); }),

11 Mar
3 months ago

gorakhyadav left a reply on Truncate Table With Foreign Key

@STEREOH - but why he is use Photo::truncate(); in code. ?

gorakhyadav left a reply on Truncate Table With Foreign Key

update your migration like this and then refresh your migration

public function up()
    {
        Schema::create('photos', function(Blueprint $table) 
            {
    $table->increments('id');
    $table->string('filename');
    $table->integer('business_id')->unsigned();
    $table->foreign('business_id')->references('id')->on('business')->onDelete('cascade');
    $table->timestamps();
         });
     }

gorakhyadav left a reply on Truncate Table With Foreign Key

Try something like this.

    DB::statement('SET FOREIGN_KEY_CHECKS=0;');
    DB::table('table1')->truncate();
    DB::table('table2')->truncate();
    DB::statement('SET FOREIGN_KEY_CHECKS=1;');
05 Mar
3 months ago

gorakhyadav left a reply on How To Write This Mysql Query Using Eloquent?

You want to like this ?

          \App\Models\Game::whereNull('deleted_at')
         ->whereBetween('started_at',[$now,$afterTomorrow] )
         ->WhereDate('started_at', '<=', $now)
          ->whereDate('finished_at', '>=', $now)
          ->orderBy('created_at', 'desc');

gorakhyadav left a reply on How To Write This Mysql Query Using Eloquent?

@alihoushyaripour

you can try this .

    $now = \Carbon\Carbon::now()->format('Y-m-d H:i:s');

$afterTomorrow = \Carbon\Carbon::today()->addDays(2)->format('Y-m-d H:i:s'); \DB::raw("select * from games whereBetween ( 'started_at',[$FromDate, $ToDate] ) orwhereBetween ( 'started_at',[$FromDate, $ToDate] )")->getValue();

gorakhyadav left a reply on How To Write This Mysql Query Using Eloquent?

Try something like this.

$users = DB::table('users') ->where('votes', '>', 100) ->orWhere('name', 'John') ->get();

gorakhyadav left a reply on How To Write This Mysql Query Using Eloquent?

use orwhere instead of or

gorakhyadav left a reply on FindOrFail();

1- find($id) takes an id and returns a single model. If no matching model exist, it returns null.

2- findOrFail($id) takes an id and returns a single model. If no matching model exist, it throws an error1.

gorakhyadav left a reply on Error In AppServiceProvider On Table Data Reading On App Installing

check your ENV file first.

DB_DATABASE=yourDBName DB_USERNAME=root DB_PASSWORD=

gorakhyadav left a reply on I Cant Retrieve Authenticated User Data

Try this

\Auth::user();

09 Aug
10 months ago

gorakhyadav left a reply on How Do I Use Associate In Laravel.

You can use like this for Example

class User {

public function customer()
{
    return $this->hasOne('Customer');
}

}

class Customer {

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

}

$user = new User($data); $customer = new Customer($customerData);

$customer->user()->associate($user); $customer->save()

02 Aug
10 months ago

gorakhyadav started a new conversation Saving Data Relationship With Sync Doesn't Work

Hello everyone i am newly in laravel and i do not know to to save data with modules and permission.This is my table

module_permissions pivot table

user_id, module_id, permission_id

And this is my request data

{ "user_id": "2", "role_id": "1", "module_id": [1,2,3], "permission_id":{ "1": [1,2,5], "2": [5,7], "3": [1,2,5] } }

and this is define relation in User Model

public function userRole() { return $this->belongsToMany('App\Role','user_roles')->withTimestamps(); }

public function userRoleModule()
{
    return $this->belongsToMany('App\Module','user_modules')->withTimestamps();
}
public function userModulePermission()
{
    return $this->belongsToMany('App\Permission','module_permissions')->withTimestamps();
}

and am saving like this

$user_id = $request->user_id; $role_id = $request->role_id; $module_ids = $request->module_id; $permission_ids = $request->permission_id;

    $user = User::find($user_id);
    if (!$user)
        return response()->json(['message' => 'error'], env('NOT_FOUND'));
    
    $user->userRole()->sync($role_id); // This is work fine
    $user->userRoleModule()->sync($module_ids); // This is work fine
  $user->userModulePermission()->sync($permission_ids ); // But This is not work 
02 Jan
1 year ago

gorakhyadav left a reply on Edit Product

Please Check php version PHP Version: 7.1.8 Database Driver & Version: mysql 5.7.19

gorakhyadav left a reply on How To Access Variable Of One Function Into Another

You NEED the collaborator, you just can't keep it in the controller since its not chained action.

gorakhyadav left a reply on HTML Line Break Interpretation Saved In SQL, From Textarea

in blade file tried these following:

{{ nl2br($words )) }} // result as described above
{{ nl2br(e($words)) }} // result as described above```

gorakhyadav left a reply on Success Massage Not Working.

thanks for reply but nothing showing in blade

gorakhyadav started a new conversation Success Massage Not Working.

am pass this in controller 
 return view('admin.users.index',compact('users','total'))->with('success','user Update successfully');

and this one in blade page
  @if ($message = Session::get('success'))
                                      <div class="alert alert-success">
                                          <p>{{ $message }}</p>

                                      </div>
                                  @endif