fylzero

fylzero

Member Since 5 Years Ago

Chicago, IL

Experience Points
204,060
Total
Experience

940 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
1608
Lessons
Completed
Best Reply Awards
63
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 41
204,060 XP
Jan
17
22 hours ago
Activity icon

Replied to Run DB Setup For CMS Only Once

@ainsley_clark There is no reason you can't run a function in your app before running a migration.

Just make a button in your interface to install it.

If you need to forum the migration from the function you can do this with console commands. Which you can call from a controller.

Activity icon

Replied to Securing Endpoint Being Used By Our Other Server

@rudexpunx It's easy to miss in the documentation because it exists in the table of contents at the bold title level... so your eye naturally scans to the smaller sub-item text in the TOC list. I can never find it when I'm looking either, so I usually just search the page for "machine-to-machine". lol

Activity icon

Awarded Best Reply on Securing Endpoint Being Used By Our Other Server

@rudexpunx If you are using Passport just use Client Credentials Grant Tokens...

The client credentials grant is suitable for machine-to-machine authentication.

https://laravel.com/docs/6.x/passport#client-credentials-grant-tokens

Depends on what you mean by not-public? Not listed in the world as an API or not available to outside networks / the general interwebs?

Activity icon

Replied to Securing Endpoint Being Used By Our Other Server

@rudexpunx If you are using Passport just use Client Credentials Grant Tokens...

The client credentials grant is suitable for machine-to-machine authentication.

https://laravel.com/docs/6.x/passport#client-credentials-grant-tokens

Depends on what you mean by not-public? Not listed in the world as an API or not available to outside networks / the general interwebs?

Activity icon

Awarded Best Reply on Validation 'not' Email

@untymage I would make sure that the use case isn't just that the user prefers to have their email be their username first. I think a lot of ppl are used to doing that now.

That said... you can validate against a reg ex pattern. Just make it alpha numeric and don't allow special characters.

https://laravel.com/docs/6.x/validation#rule-regex

Disallows special characters... you could just disallow the @ symbol... https://www.regextester.com/3319

https://stackoverflow.com/questions/5988228/how-to-create-a-regex-for-accepting-only-alphanumeric-characters/5988385

I would also make sure to just make a custom validation message that says "Username can not be an email address"

https://laravel.com/docs/6.x/validation#customizing-the-error-messages

Activity icon

Replied to Validation 'not' Email

@untymage It would... but currently not a thing as far as I know. The solution I provided will get you there.

You're not the first to suggest it...

https://github.com/laravel/framework/issues/14297

If you want it... write a PR. :)

Activity icon

Replied to Validation 'not' Email

@untymage I would make sure that the use case isn't just that the user prefers to have their email be their username first. I think a lot of ppl are used to doing that now.

That said... you can validate against a reg ex pattern. Just make it alpha numeric and don't allow special characters.

https://laravel.com/docs/6.x/validation#rule-regex

Disallows special characters... you could just disallow the @ symbol... https://www.regextester.com/3319

https://stackoverflow.com/questions/5988228/how-to-create-a-regex-for-accepting-only-alphanumeric-characters/5988385

I would also make sure to just make a custom validation message that says "Username can not be an email address"

https://laravel.com/docs/6.x/validation#customizing-the-error-messages

Jan
16
1 day ago
Activity icon

Replied to I Want My Form To Be Submitted After Successful Payment JS

@tomasosho Looks right. You might need... maybe put id="myForm" on the form tag.

function payWithPaystack(event){
    event.preventDefault();



document.getElementById('myForm').submit();
Activity icon

Replied to Dynamic Table

@mehmetanbaki You can absolutely customize these sheets with dynamic data. You create and export dynamic data using Exports right? Meaning exports you have to new-up to create an Excel file, whatever.

Simply build out your dynamic data in the Export file. Located in the app/Exports folder. This is just PHP, pass data to your cells. https://docs.laravel-excel.com/3.1/exports/mapping.html#mapping-data

WithHeadingRow will specify the column names... you can set that dynamically as well. https://docs.laravel-excel.com/3.1/imports/model.html#possible-column-names

You can make multiple sheets. https://docs.laravel-excel.com/3.1/imports/multiple-sheets.html#multiple-sheets

You'll basically want to create an edit page to add and modify data... then make a view page or pass this data to a download function. You probably won't find a working example of this as the use case is fairly specific, I'm not going to code it for you. You can figure this out. =) All the documentation you need is there.

Your question seems to be "is it possible?" The answer is yes. =)

Activity icon

Replied to Rule Of Thumb For When To Use And When To Not Use Components?

@jove Whatever seems most understandable, convenient and even more importantly... dry.

Cards are something used over and over... anything you reach for repeatedly is a good flag for use as a component.

Keep in mind you can always refactor code one way or the other. You can break out components when useful and revert to inline code when not useful.

Activity icon

Replied to Hashing And Storing Large Data In MySQL Database,

@gouseferoz Encryption does not equate with compression. To encrypt in and out of the database, the methods I suggested above are the right way to go about it. Those encryption methods are salted by your APP_KEY in your env file, it isn't one way... fairly secure for what you are trying to do.

Compressing in and out of a database... you would literally lose speed doing the compression and decompression waaaaay more than having it compressed would save you in the first place. There is a reason that isn't common practice.

Activity icon

Awarded Best Reply on How To Check The Password Before Log In

@supunsam This would be a good place to use custom middleware. You basically want to wrap a shell around your protected routes to check for this...

php artisan make:middleware DefaultPasswordCheck

app/Http/Middleware/DefaultPasswordCheck.php

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cookie;

class DefaultPasswordCheck
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // Check for default password, redirect to force change password page...
        if ( auth()->user()->password === bcrypt('password') ) {
            return redirect('/password/change/route');
        }

        return $next($request);
    }
}

Register the middleware... make sure it is at the bottom as order matters here. Auth should execute first.

app/Http/Kernel.php

protected $routeMiddleware = [
        // Everything else
        'default.password.check' => \App\Http\Middleware\DefaultPasswordCheck::class,
    ];

Then just add default.password.check middleware to your protected routes / route groups... this should also protect auth first. So they auth, then it checks for default password.

Route::get('someroute', '[email protected]')->middleware(['auth', 'default.password.check']);

If you do this instead of the login check it will actually force the user to change their password. Otherwise, just doing this on login... they could login, then just go to a different route without changing their password. Also, verifying the authed password instead of what is passed in the request is a better move. Someone might be able to just type the default password and since it passed in the request it would allow them to change a password for a user that has already changed it. This implementation will be more secure.

Hope this helps!

Activity icon

Replied to Hashing And Storing Large Data In MySQL Database,

@gouseferoz you could use the Laravel encrypt() and decrypt() helpers.

Activity icon

Replied to Can Eloquent Accept Unix Time For Date Fields?

@colin_laws It sounds like you are storing the timestamp and unix time, correct? It might be easier just to use timestamps as is and create an accessor when needed to convert the Unix time when being displayed.

https://laravel.com/docs/6.x/eloquent-mutators#accessors-and-mutators

Obviously using Carbon now() for timestamp storage and using an accessor would be much simpler and keep you from having to juggle all of this everytime.

Activity icon

Replied to Trigger Email Laravel

@fsales

https://laravel.com/docs/6.x/notifications#creating-notifications

https://laravel.com/docs/6.x/notifications#mail-notifications

Once you have mail firing... just drop the Notification in your controller using the facade. Or you can use an event/listener flow.

You may also decide to use mail if this is a more communicative email... Laracasts just put out a video about the difference between mail and notifications here...

https://laracasts.com/series/laravel-6-from-scratch/episodes/46

Activity icon

Replied to Dynamic Table

@mehmetanbaki I'm reading into this a bit trying to understand... if you are saying you want to have a table that can be editable and pass that data to laravel-excel you can definitely do that.

Just pass the array of data to a processor method that gives the data to the excel package to export it.

Activity icon

Replied to Laravel - Dynamically Add Or Remove Input Fields Using JQuery

@fsales This should be what you need. Fyi, CodePen is a great place to search for simple jQuery answers.

https://codepen.io/wailaw/pen/VWQZbb

Activity icon

Replied to How To Store Data About Trello Style Board.

@reaz One thing I can say is... think of your data in the way that a Trello board is laid out.

So you have a multidimensional array. These objects represent your columns. The order of the indices in the array determines the order of the card in the column. This is how drag and drop interfaces mostly handle sorting, just based on the array order.

Example...

$structure = {
    [0] => {
        'key' => 'column 1',
        'cards' => {
            [0] => {
                'title' => 'first card',
                'body' => 'lorem...'
            }
        }
    }
}

Dragging and dropping the card should just update the index position of the cards and columns. Assuming you are using Vue, you can just have your interface reflect these changes reactively.

Figured just giving some theory here would be helpful to visualize what needs to happen under the hood.

Activity icon

Replied to How To Check The Password Before Log In

@supunsam This would be a good place to use custom middleware. You basically want to wrap a shell around your protected routes to check for this...

php artisan make:middleware DefaultPasswordCheck

app/Http/Middleware/DefaultPasswordCheck.php

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cookie;

class DefaultPasswordCheck
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // Check for default password, redirect to force change password page...
        if ( auth()->user()->password === bcrypt('password') ) {
            return redirect('/password/change/route');
        }

        return $next($request);
    }
}

Register the middleware... make sure it is at the bottom as order matters here. Auth should execute first.

app/Http/Kernel.php

protected $routeMiddleware = [
        // Everything else
        'default.password.check' => \App\Http\Middleware\DefaultPasswordCheck::class,
    ];

Then just add default.password.check middleware to your protected routes / route groups... this should also protect auth first. So they auth, then it checks for default password.

Route::get('someroute', '[email protected]')->middleware(['auth', 'default.password.check']);

If you do this instead of the login check it will actually force the user to change their password. Otherwise, just doing this on login... they could login, then just go to a different route without changing their password. Also, verifying the authed password instead of what is passed in the request is a better move. Someone might be able to just type the default password and since it passed in the request it would allow them to change a password for a user that has already changed it. This implementation will be more secure.

Hope this helps!

Activity icon

Awarded Best Reply on How To Bind Multiple Selectbox In Table Rows

@mecjos First thing, your index I'm assuming should just be {{ index }} if you want the current count. No need to iterate that, it should be done automatically. If you really want this, incrementing is a more conventional way of doing this {{ index++ }}

To fix the multiple select issue... your select must be an array... you can pass the same index for this. You may have to init selectedState as an array.

v-model="selectedState[index]"
data() {
    return {
        selectedState: []
    }
}
Activity icon

Awarded Best Reply on Need Code To Expire PDF Download Link After 10 Mints For User.

@abdullah_iftikhar Use a temporary signed route...

use Illuminate\Support\Facades\URL;

return URL::temporarySignedRoute(
    'unsubscribe', now()->addMinutes(30), ['user' => 1]
);

https://laravel.com/docs/6.x/urls#signed-urls

Jan
15
2 days ago
Activity icon

Replied to Laravel Notifications

@beracah.kings

Model::where('user_id', $user_id)->count();

Activity icon

Replied to How To Bind Multiple Selectbox In Table Rows

@mecjos First thing, your index I'm assuming should just be {{ index }} if you want the current count. No need to iterate that, it should be done automatically. If you really want this, incrementing is a more conventional way of doing this {{ index++ }}

To fix the multiple select issue... your select must be an array... you can pass the same index for this. You may have to init selectedState as an array.

v-model="selectedState[index]"
data() {
    return {
        selectedState: []
    }
}
Activity icon

Replied to Deleting A Record From A Many To Many Relationship

@zaster Just use models... makes this super easy.

use App\DispatchItem;

public function destroy($id)
{
    $dispatchItem = DispatchItem::find($id);
    $dispatchItem->subjobs()->delete();
}

Alternately, you could use route-model binding to reference the model...

public function destroy(DispatchItem $dispatchItem)
{
    $dispatchItem->subjobs()->delete();
}

Make sure to set subjobs as a relationship on DispatchItem model...

class DispatchItem extends Model
{
    public function subjobs()
    {
        return $this->belongsToMany('App\SubJobs');
    }

...and the inverse on SubJobs...

class SubJobs extends Model
{
    public function dispatchItems()
    {
        return $this->belongsToMany('App\DispatchItem');
    }
Activity icon

Replied to Use Web Or Api Route When Building An Api.

@leostereo The difference is the way they auth out of the box. Take a look at app/Providers/RouteServiceProvider.php

If you are building an api... you should use the api routes. Using the api routes also prefixes your routes by default with /api. Where this gets really confusing is when you are building an SPA and want to use the API calls with your application and also develop a publicly documented API, or private developer API...

Basically, I would argue that you can plan this however you want. In general I tend to add my own files to RouteServiceProvider for internal ajax calls. I usually create an ajax.php and put my SPA routes there, put my API routes in API and my usually one or two web routes in web.php

Activity icon

Awarded Best Reply on How To Send Email From Lumen?

@prasadg ...

Mail::to($request->user())
    ->subject('Hi there')
    ->cc($moreUsers)
    ->bcc($evenMoreUsers)
    ->send(new OrderShipped($order));

The body will be in the OrderShipped mailable. You have to create this with php artisan make:mail OrderShipped

Activity icon

Replied to /storage/ Directory Path

@dipeshnx With the solution I provided... you could add your own env LOCAL_STORAGE_PATH and aim that wherever you want on the server. Keep your filesystem driver as local in config and override that variable with an env variable. That should do what you want. Just make sure the directory you choose has the correct read/write permissions.

...and even if you need the files to be publicly accessible, you can just symlink to your public folder.

Activity icon

Replied to /storage/ Directory Path

@dipeshnx For sure, if this helped please mark "best answer". Thanks!

Activity icon

Replied to /storage/ Directory Path

@dipeshnx Do this...

In .env...

LOCAL_STORAGE_PATH=/some/dir/path

In config/filesystems.php...

'local' => [
    'driver' => 'local',
    'root' => env('LOCAL_STORAGE_PATH'),
],

You can change this in the same way for public if you want.

In .env...

PUBLIC_STORAGE_ROOT=app/public/some/dir/path
PUBLIC_STORAGE_URL=app/public/some/dir/path

In config/filesystems.php...

'public' => [
    'driver' => 'local',
    'root' => storage_path(env('PUBLIC_STORAGE_ROOT')),
    'url' => env('APP_URL').'/'.env('PUBLIC_STORAGE_URL'), 
    'visibility' => 'public',
],

Do this in the filesystems config. That is the right place for this change to happen.

Activity icon

Replied to /storage/ Directory Path

@dipeshnx php artisan storage:link

Creates a symlink from public to storage folder so it is publicly accessible.

Alternately, you can mod your config/filesystems.php under disks to point elsewhere.


    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

        'reports' => [
            'driver' => 'local',
            'root' => storage_path('app/private/reports'),
        ],

    ],
Activity icon

Replied to Laravel Chartist-js To PDF

@seventopo Definitely possible, there is a working example on this page.

https://jsreport.net/blog/print-chartjs-into-pdf-using-phantomjs

Activity icon

Replied to How To Send Email From Lumen?

@prasadg Definitely let me know if that worked. Feel free to mark best answer here if this helped. Thanks!

Activity icon

Replied to How To Use Intervention Image Cache With S3 ?

@hotgeart Good luck with your many problems coding and in life.

Activity icon

Awarded Best Reply on Laravel Mix And Tree Shaking JavaScript

@thebigk If you aren't using Bootstrap you could easily remove jQuery ...and Lodash. Both of those libraries should halve that size at lease. Granted 305k is nothing these days. Average webpage size as of 2019 is about 3MB. Yes, 3MB! If you dont need Axios, kill that too. Laravel doesn't use these... they just include them if you want to use them.

Activity icon

Replied to Laravel Mix And Tree Shaking JavaScript

@thebigk Tree shaking happens, where supported, when you run npm run production

https://github.com/JeffreyWay/laravel-mix/issues/577

Activity icon

Replied to Laravel Mix And Tree Shaking JavaScript

@thebigk If you aren't using Bootstrap you could easily remove jQuery ...and Lodash. Both of those libraries should halve that size at lease. Granted 305k is nothing these days. Average webpage size as of 2019 is about 3MB. Yes, 3MB! If you dont need Axios, kill that too. Laravel doesn't use these... they just include them if you want to use them.

Activity icon

Replied to Getting Error: Cannot Declare Class A Because The Name Is Already In Use

@spbaniya I could be wrong... but your web route file is already published by the RouteServiceProvider. Are you sure this isn't executing twice?

Just as a test... make another route file... just call it test.php and only update to use that here. If that fixes the problem, that's your issue.

Jan
14
3 days ago
Activity icon

Replied to How To Send Email From Lumen?

@prasadg ...

Mail::to($request->user())
    ->subject('Hi there')
    ->cc($moreUsers)
    ->bcc($evenMoreUsers)
    ->send(new OrderShipped($order));

The body will be in the OrderShipped mailable. You have to create this with php artisan make:mail OrderShipped

Activity icon

Replied to Sharing Users Between Multiple Laravel Projects

@jamespavett Google on Laravel SSO. You are looking for a single sign on approach.

Some users have mentioned liking this package... https://github.com/jasny/sso

CC @heyaharmon @ftiersch

Activity icon

Replied to Api Returns "200 OK" Instead Of "401 Unauthorized"?

@stesvis What do you mean "logged out"? your API should be accepting a Bearer token... it doesn't rely on you being logged in to the site.

If this is for SPA, please specify.

Activity icon

Replied to Search Function Get Wrong Value

@adhik13th The line should be fine... what happens if you dd($ipsrs_aduan)?

Activity icon

Replied to Getting Route To Work With Vue

@pllaguno Did you import the subcomponent? You have to slot or import the subcomponent.

Activity icon

Replied to How To Send Email From Lumen?

@prasadg Lumen implemented mail same as Laravel. Use the laravel docs and follow those for Mail.

Activity icon

Replied to Scheduling

@mehmetanbaki If I understand you correctly... set a timestamp in the database using the now() helper. Then just check on page load...

$user = auth()->user();

if ($user->timestamp_field->isPast()) {
    // show thing expired
}
Activity icon

Replied to How To Use Intervention Image Cache With S3 ?

@hotgeart Your question...

How can I pass an url from Digital Ocean Space or S3?

Activity icon

Awarded Best Reply on Google Maps

@mehmetanbaki To convert an address to latitude and longitude you'll need to use the Geocode API as well... here is a controller I built to do this...

<?php

namespace App\Http\Controllers;

class GoogleMapsController extends Controller
{

    public function getCoordinates()
    {

        // URL Encode is needed to pass to URL below
        $address = urlencode( '233 S Wacker Dr, Chicago, IL 60606' );

        // Set URL with Address and Key to Geocode API
        $url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.$address.'&key='.env('GOOGLE_MAPS_SERVICE_KEY');

        // Get the repsonse from the API, convert JSON to Array
        $resp_json = file_get_contents($url);
        $resp = json_decode($resp_json, true);

        // Parse Latitude and Longitude
        $lat = isset($resp['results'][0]['geometry']['location']['lat']) ?: null;
        $long = isset($resp['results'][0]['geometry']['location']['lng'])?: null;

        // Pass resulting data to view or whatever...  $data['lat] and $data['lng']
        $data = [
            'lat' => $lat,
            'lng' => $long,
        ];

        // If you want to return JSON...
        return json_encode($data);

    }

}

https://developers.google.com/maps/documentation/geocoding/intro