mushood

mushood

Member Since 2 Years Ago

Port Louis

Back End Web Developer at Esokia Web Agency ltd

Experience Points 136,050
Experience Level 28

3,950 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 950
Lessons
Completed
Best Reply Awards 64
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
4 days ago

mushood left a reply on Remember_me Token Not Being Set

Thank you @gorakhyadav However, this is not the answer I am looking for. The problem right now is that the remember_me token is not being set in the browser of the user BUT it is correctly generated though.

15 Mar
5 days ago

mushood started a new conversation Expected Remember_me Functionality

When I login, i have the option of either ticking the remember box or not. I want to walk through both scenarios to see if I got them right:

  1. NOT CHECKING THE BOX

A/ I login and only a session cookie is set.

B/ I can navigate to different pages.

B.1/ If this session cookie expires due to inactivity for example, when I come back and refresh on an authentication-required page, I will land on the login page.

B.2/ If I close the browser, when I open the browser again, if I go to authentication-required page, I will land on the login page.

  1. CHECKING THE BOX

A/ I login and a session cookie is set as well as a remember_me cookie is set.

B/ I can navigate to different pages.

B.1/ If this session cookie expires due to inactivity for example, when I come back and refresh on an authentication-required page, I will NOT land on the login page. Instead since the remember_me cookie is set, it will auto login, and redirect me to my page.

B.2/ If I close the browser, when I open the browser again, if I go to authentication-required page, I will NOT land on the login page. Instead since the remember_me cookie is set, it will auto login, and redirect me to my page.

If that how this should works? Especially the part when you close the browser and reopen after.

mushood started a new conversation Remember_me Token Not Being Set

Laravel 5.7

I used laravel auth for my login and I can't get the remember_me functionality to function correctly.

The facts:

  1. I have the remember_token column in my database
  2. When I check the remember_me checkbox, a token is saved in this column
  3. When i check the request in chrome developer tools, I see the csrf token, the session token and NO other tokens
  4. I also have passport installed in my project. Not sure if this is relevant
  5. In my session.php, I have
'expire_on_close' => true,
'driver' => env('SESSION_DRIVER', 'file'),    // set as cookie in .env
11 Mar
1 week ago

mushood left a reply on Truncate Table With Foreign Key

instead of truncate, you can use

Business::where('id', '>', 0)->delete();

This will delete all business AS LONG AS you don't have any photos with this business id

You can do something like this.

public function updateAll(Request $request)
{
    Photo::truncate();
Business::where('id', '>', 0)->delete();

    foreach($request->businesses as $business){
        Business::create([
            'id' => $business['id'],
            'title' => $business['title'],
            'description' => $business['description'],
            'order' => $business['order'],
            'visiblity' => $business['visiblity'],
            'lang' => $business['lang'],
        ]);
    }
    return response('Update Successful.',200);
}
08 Mar
1 week ago

mushood left a reply on Selecting Row Number 2

Try 'offset' instead of skip

mushood left a reply on Data From Controller To View Question.

Use a local scope for status https://laravel.com/docs/5.8/eloquent#local-scopes

//in lead model
    public function scopeOfStatus($query, $status)
    {
        return $query->where('status', $status);
    }

then this

$lead->o_total   = Lead::where('status', 'Open')->sum('estimated');

Becomes

$lead->o_total   = Lead::scopeOfStatus( 'Open')->sum('estimated');

You can apply something similar for sum('estimated')

mushood left a reply on Is The Id Of A Model Guarded By Default?

If you defined a $guarded property, you NEED to add the ID as well.

It is guarded by default. But if you defined the $guarded property, thats like say, guard ONLY what I have defined. If you dont include ID, its not guarded.

mushood left a reply on SPA Vs Multi Page Application

SPA are not for best SEO wise. If it is a client facing, I would suggest a Multi page application and add vue components like @rameezisrar mentioned.

However, if only used by admin, totally go for SPA. The user XP is most of the time superior. If you have use data. Limit the number of results of your queries. Once this is loaded, fetch the next batch. Custom pagination if necessary.

mushood left a reply on How To Write Custom Redirect Path After Logout In Default Auth Logincontroller.php

You can have a custom logout function

public function customLogout() 
{
    $user = Auth::user();

        $route = '/home';
    
    if (Auth::check() && Auth::user()->role == 3) {
            $route = '/customerhome';
    }
    elseif (Auth::check() && Auth::user()->role == 2) {
            $route = '/vendorhome';
    }

    Auth::logout();

return redirect($route);

}

Two things though:

Try to use named routes

Try to not have multiple returns in your code. See how I did it above.

mushood left a reply on Selecting Row Number 2

Model::skip(1)->limit(1)->get();
07 Mar
1 week ago

mushood left a reply on Stuck On A 3rd Party Project And Need Some Help

The structure for translation is like this:

/resources
    /lang
        /en
            messages.php
        /es
            messages.php

https://laravel.com/docs/5.8/localization

I suppose for you, it should be like this

/resources
    /lang
        /en
            /navs/
            general.php
                    

mushood left a reply on Stuck On A 3rd Party Project And Need Some Help

Ahh I feel your pain. Been through that before.

The way i went about it was to look at my routes file, then moved from one route to another to understand what was happening and make sure its working.

Try to isolate your problems and ask questions about a specific problem. It is difficult to help you if we dont know the exact problems (idealy different post for different problems -- people tend not to answer LONG LONG questions)

For example the menus, they are displayed as "menus.backend.settings.activities". Show the codes for the blade layout. and controller as well.

For the links, how are they generated? It is using the APP_URL which needs to be defined in your.env ?

mushood left a reply on Laravel Mail Editor (Mailables Editor)

Will definitely check this out!

mushood left a reply on Laravel Collectivity Is Not Work 5.8 Version ? The Site Is Off . So How To Do Use It Or Project Develop Without Laravel Collectivity ? Response Skilled Person . About Laravel ..

@towhid Its better if you don't use it at the moment since they are reworking it and making it laravel agnostic as they say.

The framework also moved away from collective since it is easier to use HTML forms and also much more flexible.

06 Mar
2 weeks ago

mushood left a reply on How To Use V-if Inside V-for

<tr v-for="(item,index,i) in actionDetails">
<td v-if="index.includes('date')">{{ item |   moment('DD/MM/YYYY') )</td>
<td v-else> {{ item }} </td>
 </tr>

mushood left a reply on How To Use V-if Inside V-for

General Example

<tr v-for="(item,index,i) in actionDetails">
<td v-if="index == startdate">{{ item | moment('DD/MM/YYYY') )</td>
<td v-else> {{ item }} </td>
 </tr>

mushood left a reply on How To Link Language File

From the docs: https://laravel.com/docs/5.8/localization#retrieving-translation-strings

There is not Linking as such required.

Laravel's localization features provide a convenient way to retrieve strings in various languages, allowing you to easily support multiple languages within your application. Language strings are stored in files within the resources/lang directory. Within this directory there should be a subdirectory for each language supported by the application:

/resources
    /lang
        /en
            messages.php
        /es
            messages.php
All language files return an array of keyed strings. For example:

From this, you simply need to place the file in the correct file tree and you should be good to go. Based on your App:locale, it will automatically retrieve the key from the correct file, using the fallback locale where necessary.

05 Mar
2 weeks ago

mushood left a reply on How To Post Full Coding Here Without Being Cut?

For syntax highlighting: https://help.github.com/en/articles/creating-and-highlighting-code-blocks

As for pictures, you can upload the picture somewhere like https://imgur.com/upload and then share the link.

mushood left a reply on Login Expires And Shows Private Data

If you set a window.setInterval in JS, not sure it runs when you reopen the browser.

Also if you keep making requests to the server, you will keep being authenticated.

mushood left a reply on Adding Progress Bar To File Upload

If you validation and insertion is a job, you can maybe use this: https://github.com/imTigger/laravel-job-status

If you use Mattexcel for the file processing, you can use this: https://docs.laravel-excel.com/3.1/imports/progress-bar.html

mushood left a reply on Login Expires And Shows Private Data

I believe this is more an issue of the browser caching the page than with laravel auth

mushood left a reply on Laravel Queues - Class Dispatch Does Not Exist

I would suggest to change your driver to database: https://laravel.com/docs/5.7/queues#driver-prerequisites

Check if your job is actually being created in your local db. If it is, it is a config issue with Redis and Horizon (Have not used either, so can't advise)

but if the job is not being created in local db, problem with your job code Make sure that Dispatchable is this one: use Illuminate\Foundation\Bus\Dispatchable;

You can also try to use this syntax instead

dispatch((new ImportDocuments(stream))
01 Mar
2 weeks ago

mushood left a reply on Auth::check() In Middleware Keeps Return False

@zxtanzxzx That happens. I would suggest in your spare time to still try to dig in and find out why its not working. There might be a good lesson in this. Keep me updated if you find anything.

mushood left a reply on Laravel Api | Social Networking | Vuejs

@talhaatsix I would suggest that you take a look at policies and gates: https://laravel.com/docs/5.7/authorization

Its a very useful concept to learn and can you in this specific case.

mushood left a reply on How To Insert Records In Two Tables From Single Form

As promised, here are some pointers to guide you towards the answer

First thing, your jQuery, you cannot use {{ old('sc_desc') }} since this is rendered on the server side and jQuery is used client side. Let me know if you understand these terms.

For you specific use case, you need to be able to :

A/ handle multiple values from your form (in your store function) b/ use jQuery to be able to add/remove multiple categories c/ handle validation errors on server side and render the form back with old values

Lets start with step 1

<form method="POST" class="form" role="form" action="{{route('category.store')}}">
                    @csrf
                    <div class="form-row">
                        <div class="form-group col-md-4">
                            <label for="c_id">Category ID</label>
                            <input class="form-control" name="" type="text">
                        </div>
                        <div class="form-group col-md-4">
                            <label for="c_date">Category Date</label>
                            <input class="form-control" name="c_date" type="date"  required>
                        </div>
                        <div class="form-group col-md-4">
                            <label for="c_name">Category Name</label>
                            <input class="form-control" name="c_name" type="text" required>
                        </div>
                        <div class="form-group col-md-12">
                            <label for="c_desc">Category Description</label>
                            <textarea name="c_desc" class="form-control" rows="3" required></textarea>
                        </div>

                        <div class="card-header">Add Sub Category</div>
                        <table class="table">
                            <thead>
                                <tr>
                                
                                <th>SubCategory Name</th>
                                <th>Subcategory Description</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody class="resultbody">
                                <tr>
                                    <td>
                                        <input type="text" class="name form-control" name="sc_name[]">
                                    </td>
                                    <td>
                                        <input type="text" class="fname form-control" name="sc_desc[]">
                                    </td>
                                    <td>
                                        <button class="btn btn-danger delete">Remove</button>
                                    </td>
                                </tr>
                <tr>
                                    <td>
                                        <input type="text" class="name form-control" name="sc_name[]">
                                    </td>
                                    <td>
                                        <input type="text" class="fname form-control" name="sc_desc[]">
                                    </td>
                                    <td>
                                        <button class="btn btn-danger delete">Remove</button>
                                    </td>
                                </tr>
                            </tbody>
                        </table>    

                    <button class="btn btn-success btn-lg " type="submit">SUBMIT</button>
</form>

Try the form WITHOUT any jQuery and see if you can actually receive multiple values for sc_name on server side when you dd the request.

Once this is working, we can move on to the jQuery side.

mushood left a reply on How To Insert Records In Two Tables From Single Form

i'll need more time to formulate a correct answer

@akmahato Should be free in around 8 hours, if no one replies.

mushood left a reply on Auth::check() In Middleware Keeps Return False

@zxtanzxzx

I checked this out: https://laracasts.com/discuss/channels/laravel/how-can-i-access-the-authuser-in-a-middleware-class?page=1

Alternatively, you can add it to your web middleware:

        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \App\Http\Middleware\AdminLoginControl::class,
        ],

mushood left a reply on Auth::check() In Middleware Keeps Return False

No it should be after

    protected $middlewarePriority = [
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\Authenticate::class,
        \Illuminate\Session\Middleware\AuthenticateSession::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        \Illuminate\Auth\Middleware\Authorize::class,

        \App\Http\Middleware\AdminLoginControl::class,

    ];

also in your route middleware

protected $routeMiddleware = [
    'auth' => \App\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
    'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
    'can' => \Illuminate\Auth\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
    'admin' =>  \App\Http\Middleware\AdminLoginControl::class,
];

mushood left a reply on Auth::check() In Middleware Keeps Return False

What is happening here is that your middleware is running before the middleware responsible for authenticating the user

In your app/Http/Kernel, specify the middleware priority by adding your middleware AFTER

mushood left a reply on Getting The Invoice Number To Go To Cancel Function

Try this:

<input type="hidden" name="cancel_url" value="{{ route('payfast.cancel', [ 'invoice_number' => $invoice_number]) }}">

mushood left a reply on Laravel Api | Social Networking | Vuejs

Yes this is possible in laravel

As for the other questions, it would take quite some time to answer each and answering them for you would take away from your learning. Could you say what you would do for each of those questions and then we could point you in the correct direction.

For question 2, take a look at laravel passport: https://laravel.com/docs/5.8/passport

Happy learning

mushood left a reply on How To Insert Records In Two Tables From Single Form

Are you using eloquent and have models for your Category and SubCategory?

Post the following codes on your side please:

  1. Form code

  2. Route code

  3. Controller code

In your controller, it could look like this

postFunction(Request $request)
{
        $category = new Category();
    $category->c_name = $request->name;
    $category->c_desc -> $request-> desc
    $category->save();

        $subCategory = new SubCategory();
    $subCategory->category_id = $category->id;
    $subCategory->c_name = $request->name;
    $subCategory->c_desc -> $request-> desc
    $subCategory->save();
}
28 Feb
2 weeks ago

mushood left a reply on How Correctly To Replace Auth Module With Passport ?

The documentation is quite clear on what you need to do.

Start doing it and then post on the forum more specific issues that you are having. Will be easier to help you.

If you are completely lost, start by transfering your routes to the routes/api.php file then follow this specific part to protect your user: https://laravel.com/docs/5.7/passport#protecting-routes

Take your time to understand passport. Its very useful to master this.

mushood left a reply on UI And Data Structure For Array Of Dates

I had a 1:n relationship with Task Model and "Schedule Model" The schedule model has a type variable where I define which type it was

As for UI, a button to "add new" to add multiple times, with the option to add a start and end time. On the form, i showed one row for this by default because it was required for me to have at least one time schedule for each task.

Hope this helps.

mushood left a reply on Convert Array (key, Value) To Flat Array

Try this:

$oldArray = [
"firstname" => "Zulauf",
"city" => "washington",
"lastname" => "emrod"
];

$newArray = [];
foreach ($oldArray as $key => $element) {
$newArray[] = [$key, 'like', $element];
}

Notice the $key => $element to access both $key and $element

You should try to look into php arrays a bit more. This seems a little bit straight forward

24 Feb
3 weeks ago

mushood left a reply on Which Relationship Would You Choose?

@yoeriboven Definitely option 1

Having two pivot tables can lead to data inconsistencies. As a good practice, never save the same information twice in your database.

You can define a function called post() in your user model

public function user()
{
    $profileIds = $this->profiles->pluck('profile_id');
    $posts = Post::whereIn('profile_id',$profileIds)->orderBy('created_at','DESC')->get();

    return $posts;
}

Then call $user->posts();

22 Feb
3 weeks ago

mushood left a reply on Splitting Code For A Project That Only Uses Vue On Several Pages

this looks right.

Also its not ugly. Its what is required in your specific case and a quite clean way at that.

mushood left a reply on Which Relationship Would You Choose?

Can a user have many profiles? Can two users have same profile?

I think user to profiles should be one to many

Then option 1 is preferred.

mushood left a reply on Multi-tenancy Best Practices

I best explain this as an example

Lets say you have a User model which is shared by Site A and site B

You can create a composer package with this user model.

Require this composer package in Site A and Site B.

In each site, set their User Model that extends the package User Model. This way, you can sync files across projects.

Some extra work of course, but saves time in the long run. Plus you get to keep your initial structure.

mushood left a reply on Splitting Code For A Project That Only Uses Vue On Several Pages

Do try, in your webpack.mix.js

mix.js('resources/js/vendor.js', 'public/js').js('resources/js/home.js', 'public/js').js('resources/js/order-index.js', 'public/js')

not sure if can split Vue out the order-index.js

Do keep this thread updated. Interested in knowing how you got around it.

21 Feb
3 weeks ago

mushood left a reply on SSH Login Not Working

@temwa I think the best bet is to talk to forge assistance. They are usually responsive.

mushood left a reply on SSH Login Not Working

Make sure that the key is enabled for connection on the server Also make sure that bash access is enabled on the server

For the command the structure is usually like this

ssh -i path/to/privatekey [email protected]

mushood left a reply on Multiple Models Query And Order Optimization

I think what you are looking for here is the union mysql command

LInk to understand how union works: https://stackoverflow.com/questions/6790479/select-separate-rows-from-two-tables-order-by-date

As for eloquent queries: https://laravel.com/docs/5.7/queries#unions

mushood left a reply on Use POST Request For Update Routes

While its just semantics like Snapey said, when people use your update routes, they will look for put/patch. If they can't find it, they will figure out its the post route. Conventions just make things easier to understand when working in group.

mushood left a reply on Queues In Block

Create a model called Tracker with the following fields: id, no_of_users, success_count, failed_count, failed_jobs

  1. the no_of_users is the number of emails to be sent.
  2. The success_count is the number of successful emails sent
  3. the failed_count is the number of failed jobs
  4. the failed_jobs is a json of the ids of users not sent the email

When you do a bulk action, create a new tracker with the details. Then dispatch several individual jobs. After each job, update the tracker. If the job fail, update tracker and add to failed jobs.

You can then see which exactly fail. You can then retry them if necessary.

Once all emails is sent, delete the tracker

Just an idea. Hope this helps guide you.