Shahrukh4

Shahrukh4

Member Since 1 Year Ago

Allahabad, India

Web Developer at Noida, India

Experience Points 10,800
Experience Level 3

4,200 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 67
Lessons
Completed
Best Reply Awards 4
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.

20 Feb
2 months ago

Shahrukh4 left a reply on How To Make List Values Available For Multiple Controllers (drop Down View)

@ROBOROBOK - Yeah that will be great if you are using the data specifically for any main view. I suggested that idea if you are dealing with some data required in multiple views such as navbars, sidebars etc. which loads everytime your main view loads.

Shahrukh4 left a reply on How To Make List Values Available For Multiple Controllers (drop Down View)

@CEMCMINN - It's all right. Yes ofcourse you can set as many things as you want, the with() for view is taking an array.

Shahrukh4 left a reply on Run In Background Artisan Schedule On Windows

@ORICEON - Then you can use logs to check the step by step debugging.

Shahrukh4 left a reply on Run In Background Artisan Schedule On Windows

Then you can use logs to check the step by step debugging.

Shahrukh4 left a reply on Authentication Using Socialite

@RANYL - Look closely, there is definetly redirect not defined. search it and fix it as per your code.

Shahrukh4 left a reply on Multiple Roles But Shared Models / Controllers

It's all right, have a good day.

Shahrukh4 left a reply on Laravel 5.4: Return Response Json GroupBy Created_at With Static Key For Each Group

You don't have to pull in dingo api, you just need to use fractal transformer.

Shahrukh4 left a reply on Laravel 5.4: Return Response Json GroupBy Created_at With Static Key For Each Group

If you want that then you can transform data as in desired format. Read Fractal Transformers for this.

Shahrukh4 left a reply on Laravel Join 3 Tables , One Data From First Two Table And Multiple Row From Third Table

Actually you don't need to put additional journal_id in your articles table. volume_id is sufficient to take data out in whichever way you like through journal->volume->article or so.

Shahrukh4 left a reply on Job Chaining - Accessing Modified Eloquent Model

As a matter of fact, Laravel jobs don't handle files to be uploaded. You must have upload this file locally in any of your folders first and only then you can give path of the file location. In this way you can manipulate this file.

Shahrukh4 left a reply on Laravel Auth Multiple Databases

If you have multiple database to deal with, then all you need is the Multi-Auth system for your app which laravel can very easily manage. Try to go through the following references. Medium Laravel Multi Auth

Package for Multi Auth

Like in the above references, if you manage the auth() for various database by creating various middlewares for each you can achieve that.

Shahrukh4 left a reply on Authentication Using Socialite

1). It seems you didn't setup the redirect URL for the socialite from .env or config/services.php. 2). Go to your config/services.php and set your return url at which it should come up after the transaction.

'facebook' => [
    'client_id'     => env('FACEBOOK_ID'),
        'client_secret' => env('FACEBOOK_SECRET'),
        'redirect'      => env('FACEBOOK_URL', http://localhost:8000/*YOUR ENDPOINT*),
],

3). For more information you can through the Socialite documentation.

Shahrukh4 left a reply on Run In Background Artisan Schedule On Windows

It seems your code is properly there but you didin't set the cron yet. Try setting up the cron on windows and I hope everything will work great.

Windows tasks

Shahrukh4 left a reply on Queued Mail Notifications Not Sent

1). You should make the QUEUE_DRIVER to sync and send the notifications. If there were any errors then it will show up.

2). If no error come up and you job executing successfully and all jobs removed from jobs table, then there must be problem in your code because everything is working great upto this point.

Shahrukh4 left a reply on Jenssegers/Mongodb

You should go through the Moloquent documentation once and then the query will be same as in normally for MySQL database.

Moloquent

Shahrukh4 left a reply on Laravel 5.4: Return Response Json GroupBy Created_at With Static Key For Each Group

Hii @johnef_sh I think you can use Laravel's map() to add your custom key for the response like follows,

public function index() {
    $poLists = ( new PurchaseOrder() )
        ->where( 'needed_quantity', '>', 0 )
        ->where( 'supplier_id', $this->guard()->user()->id )
        ->get()
    ->groupBy( function ( $item ) {
        return [ $item->created_at->format( 'Y-m-d HH:mm:ss' ) ];
        });
    
    //This will create/transform your data
    $lists = $poLists->map(function($obj){
        $data = [
            'date' => $obj
        ];

        return $data;
    });

        return response()->json( $lists, 200 );
    }

Shahrukh4 left a reply on Multiple Roles But Shared Models / Controllers

1). As for now you are building the query right.

2). It can be done by some other way or more laravel way as follows,

$users = User::query();

$query->when(auth()->user()->hasRole('reseller'), function($query){
    $query->whereHas('company', function($q) {
            $q->where('reseller', auth()->user()->company_id);
    });
})
->when(auth()->user()->hasRole('supervisor'), function($query){
    $query->where('company_id', auth()->user()->company_id );
});

$users = $query->paginate(10);

3). Or you can use Gates and Policies to restrict the view as per user roles, directly in your blades. Read the following referance for Gates and Policies. It is like more advance Laravel way to restrict views. Laravel

Shahrukh4 left a reply on How To Make List Values Available For Multiple Controllers (drop Down View)

I think you need to get the states value in all your views, If so then you can retireve all the states once in the AppServiceProvider and get it in every view as per your requirements. Try following code.

1). Go to app/Providers/AppServiceProvider.php and put following code.

<?php

namespace App\Providers;

use App\State;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot(){
        /**
         * Making current available product to buy tickets for all the pages
         */
        view()->composer('*', function ($view) {
            $states = State::pluck('name', 'id');

            $view->with([
                'states' => $states
            ]);
        });
    }

**2). **Now this $states variable is available in all your views by-default. **3). ** You can get current user's state via Auth()->users()->state and make that selected as default and $states variable to populate the drop-down.

19 Feb
2 months ago

Shahrukh4 left a reply on Laravel 5.5 Event Queue - 255 Attempts And Freeze, Not Moved To Failed_jobs

Hii @mharkrollen , It seems your no. of tries still not stick to 1 as the attempt is going upto 255. Try following things,

1). Use command to make failed_jobs table

php artisan queue:failed-table
php artisan migrate

2). Use command php artisan queue:work --tries=1 if running with terminal. If using supervisor or so you can directly hardcode the no. of tries inside the Job class as public variable.

class SendBulkMails extends Job{
    /**
     * The number of seconds the job can run before timing out.
     *
     * @var int
     */
    public $tries = 1;

    public function handle(){
    //your code goes here
    }
}

2). Use try-catch to handle the error if you can, otherwise remove all try-catch and let job fail so after a single try it will fall into failed_jobs table.

You can use the following reference Laravel Queues

Shahrukh4 left a reply on One To Many Relationship Logic

@VILFAGO - Yes ofcourse if you follow the naming convention properly, then Laravel will take care of other things.

Shahrukh4 left a reply on Making A Laravel 5.4 Query On A JSON Field Containing A JSON Array

@MARKLL - @markll like queries will slow it down. Try something that retrieve data faster. but yeah like queries will work.

24 Oct
5 months ago

Shahrukh4 left a reply on PHP Fatal Error: Class 'TestCase' Not Found

use the dependancy on the top of your class as follows,

use Tests\TestCase

class UserTest extends TestCase{

    ...//your business logic

}

Shahrukh4 left a reply on Cannot Run Php Artisan

I figured out the problem, when you are running any artisan command you should avoid using helper functions in any of your config files. Just comment those and try to run artisan command after running that uncomment your config files.

//*in config/'any_file.php'*
return [
    'name'  => 'Larvel',
    'url'       => url('/)
];

//*just change and uncomment url() helper*
return [
    'name'  => 'Larvel',
    //'url' => url('/)
];
17 Sep
7 months ago

Shahrukh4 left a reply on How Can I Solve Target [App\Repositories\NewsRepository] Is Not Instantiable While Building [App\Http\Controllers\Member\NewsController].?

Don't bind your interface in the register method, just add like follows in boot method

$model = \App\News::class; //belongs to User module

$this->app->bind('\App\Repositories\NewsRepository', function() use ($model){
    return new NewsRepositoryEloquent(new $model);
});

then run following commands in sequence,

1). php artisan config:clear 2). php artisan clear-compiled 3). php artisan config:cache

03 Sep
7 months ago

Shahrukh4 left a reply on Array On Where Clause

As a matter of fact whereIn() works on OR condition, it will not work correctly if the user want it on AND condition @tomopongrac

10 Aug
8 months ago
08 Aug
8 months ago

Shahrukh4 left a reply on Route Is Not Loading On Adress Bar

Try something like follows, may be it will work

public function valuepass(Request $request)
{   
    $person_type = $_GET['person_type'];
    $company_id = $_GET['company_id'];

    dump($person_type);
    $allentryfields = DB::table('fields')
                    ->where([['fields.company_id',$company_id],['fields.person_type',  
                    $person_type]])
                    ->join('field_types','fields.field_type_id','=','field_types.id')
                    ->select('fields.id as field_id','fields.field_name as 
                    field_name','field_types.type_name as type_name')
                    ->get();

    return Redirect::to('admin/academicuser/create/'. $allentryfields);

}

then in route change to this,

Route::get('admin/academicuser/create/{data}','AcademicUserEntryCo[email protected]');

and then in your controller,

public function valuepass($data){
    dd($data);
}

or

public function valuepass(Request $request){
    dd($request->data);
}
07 Aug
8 months ago

Shahrukh4 left a reply on Phpmyadmin 404 Not Found

Try giving the storage directory of your project some some read/write permissions. You can try running this command, Hope this will work.

sudo chmod -R 0777 storage/

Shahrukh4 left a reply on How Can I Display An Image From Database.

Actually this url() will retrieve the image path from route images/university/image which must be define in your web.php and there must be any controller logic which returns the full image path, only then this will work.Hope this will work.

Shahrukh4 left a reply on Route Is Not Loading On Adress Bar

Actuall you are just returning the view itself thats why it does not showing in address bar, try redirecting to another route which will further move to this view and I hope all will work just fine.

public function valuepass(Request $request)
{   
    $person_type = $_GET['person_type'];
    $company_id = $_GET['company_id'];

    dump($person_type);
    $allentryfields = DB::table('fields')
                    ->where([['fields.company_id',$company_id],['fields.person_type',  $person_type]])
                    ->join('field_types','fields.field_type_id','=','field_types.id')
                    ->select('fields.id as field_id','fields.field_name as field_name','field_types.type_name as type_name')
                    ->get();

    return Redirect::to('admin/academicuser/create');

}

you can found more info to [this]{} url

03 Aug
8 months ago

Shahrukh4 left a reply on Artisan Command On Cpanel

Actually in Cpanel no commands for php and composer related run because everytime you upload your projects on Cpanel you have to compile it down in your local and then upload it.

Alternatively, get the SSH access from your Cpanel and after successful SSH login try running your various artisan commands you want.

Shahrukh4 left a reply on How To Use Api Data In Blade View

You can call your API's through AJAX in your blades scripts and then loop through all the data as required. Actually API are not meant to be consumed directly by view(). You have to cosume it via some AJAX request.

Shahrukh4 left a reply on Laravel Vs Lumen For REST Api

My personal suggestion goes for lumen if you want fast response and have not too many things in project. If there are only CRUD operations then you must go for Lumen. If it is a huge application then you can try Laravel for that.

31 Jul
8 months ago

Shahrukh4 left a reply on Making A Laravel 5.4 Query On A JSON Field Containing A JSON Array

@nikocraft actually your JSON data is not formatted correctly, you can store it in the following way

//for single object
{
    "0eb2edf0-50cb-44ff-a0a6-b2a104a9dc12"
}

//for multiple object
[
    {"0eb2edf0-50cb-44ff-a0a6-b2a104a9dc12"},
    {"0eb2edf0-50cb-44ff-a0a6-b2a104a9dc12"},
    {"0eb2edf0-50cb-44ff-a0a6-b2a104a9dc12"}
]
30 Jul
8 months ago

Shahrukh4 left a reply on Multiple Table Compact Is Not Working

You can do it without using compact() if you want to,

$hostnames = HostName::all();
$visitorType = VisitorType::all();

return view('view.action', [
    'hostnames'  => $hostnames,
    'visitorType'   =>  $visitorType
]);

Shahrukh4 left a reply on Pagionate Not Showing Link

You cannot apply the paginate() inside the eager loaded query, you have to apply it always on the parent query where you started to write query. As in your case it is article where your paginate() applies on.

$articles =Article::whereHas('user',  function($query) use ($user_id){
   $query->where('id', $user_id);
})
->paginate(10);

Shahrukh4 left a reply on Where In Multiple Columns

I wil take care of that.

27 Jul
8 months ago

Shahrukh4 left a reply on Issue With WithCount() Function

Of course, you can pass a closure for withCount() too just like you do in with(), e.g as follows which gives visit count of user_id 1 on product_id 1

User::where('id', 1)
->withCount(['visits'=> function($q) use ($product_id){
    $q->where('product_id', $product_id);
}])
24 Jul
8 months ago

Shahrukh4 left a reply on Sorting Array Of Objects

If you have a collection, and you want to sort it on basis of any of it's key, then you can use the following piece of code.

//if you want to sort in ascending order
$unique     = $collection->unique()->sortBy('YOUR_KEY_TO_SORT');

//if you want to sort in descending order
$unique     = $collection->unique()->sortBy('YOUR_KEY_TO_SORT',  SORT_REGULAR,  true);

Shahrukh4 left a reply on Sorting An Array Of Collections By The Property Of Their Relationship Object

If you have a collection, and you want to sort it on basis of any of it's key, then you can use the following piece of code.

//if you want to sort in ascending order
$unique     = $collection->unique()->sortBy('YOUR_KEY_TO_SORT');

//if you want to sort in descending order
$unique     = $collection->unique()->sortBy('YOUR_KEY_TO_SORT',  SORT_REGULAR,  true);
04 Jul
9 months ago

Shahrukh4 left a reply on How To Stop Eloquent Trying To Set Updated_at

just declare the public timestamp variable to false and everything will work great.

public $timestamps = false;
14 Jun
10 months ago

Shahrukh4 left a reply on Where In Multiple Columns

exactly what I am looking for, Thanks @shez1983

13 Jun
10 months ago

Shahrukh4 left a reply on Eloquent Getting Subcategories From The Categories

place the following code inside your model

public function subCats()
{
    return $this->hasMany(self::class, 'parent_id', 'id');
}

write the following query in your controller,

$data = $this->category
->where('parent_id', '!=', null)
->whereHas('subCats')
->with('subCats')
->get()

Shahrukh4 left a reply on Get Category List (including Multiple Subcategories) Of An Article

place the following code inside your model

public function subCats()
{
    return $this->hasMany(self::class, 'parent_id', 'id');
}

write the following query in your controller,

$data = $this->attribute
->where('parent_id', '!=', null)
->whereHas('subCats')
->with('subCats')
->get()

Shahrukh4 left a reply on Get All Products From Category(and Sub-categories)

place the following code inside your model

public function subCats()
{
    return $this->hasMany(self::class, 'parent_id', 'id');
}

write the following query in your controller,

$data = $this->attribute
->where('parent_id', '!=', null)
->whereHas('subCats')
->with('subCats')
->get()
12 Jun
10 months ago

Shahrukh4 left a reply on Installing JWT Auth On Lumen 5.4

  • place "flipbox/lumen-generator": "^5.6", in your composer.json and run composer update

  • place following code in bootstrap/app.php

$app->routeMiddleware([
     'jwt' => App\Http\Middleware\JwtMiddleware::class,    
]);
  • Write following lines in your desired controller
use App\User;
use Firebase\JWT\JWT;
use Firebase\JWT\ExpiredException;

class YourController extends Controller{
        /**
         * Create a new token.
         * 
         * @param  \App\User   $user
        * @return string
        */
        protected function jwt(User $user) {
            $payload = [
                'iss' => "lumen-jwt",                     // Issuer of the token
                'sub' => $user->id,                      // Subject of the token
                'iat' => time(),                        // Time when JWT was issued. 
                'exp' => time() +  config('jwt.app.ttl')// Expiration time
            ];
            return JWT::encode($payload, config('jwt.app.secret'));
       }

       /**
         * Authenticate a user and return the token if the provided credentials are correct.
         * 
         * @param  \App\User   $user 
         * @return mixed
         */
        public function authenticateUser(Request $request) {
              $this->validate($request, [
              'email'     => 'required|email',
              'password'  => 'required'
         ]);

        // Find the user by email
        $user = User::where('email', $request->input('email'))->first();
        if (!$user) {
            return response()->json([
                'error' => 'Email does not exist.'
            ], 400);
        }
        // Verify the password and generate the token
        if (Hash::check($request->input('password'), $user->password)) {
            return response()->json([
                'token' => $this->jwt($user)
            ], 200);
        }
        // Bad Request response
        return response()->json([
            'error' => 'Email or password is wrong.'
        ], 400);
    }
}
  • Write following code in your routes/web.php file,
$router->group(['middleware' => 'jwt'], function () use ($router) {
    $router->post('users', function(){
            return App\User::all();
    });
});