kingshark

kingshark

Member Since 1 Year Ago

Chengdu, China

Experience Points
6,100
Total
Experience

3,900 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
31
Lessons
Completed
Best Reply Awards
4
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 2
6,100 XP
Jun
01
23 hours ago
Activity icon

Replied to Override Package Method (mewebstudio / Captcha)

you know what, I copied all your implementation to a demo project, and works fine. if i use Captcha::create(), it will print your "no".

There are only one thing you didn't mentioned here, you can check, that in config/app.php, for this part

'providers' => [
        // ...
        'Mews\Captcha\CaptchaServiceProvider',
    ]

have you changed this to your custom provider? if not, the original provider will be registered but yours are not so no effect at all.

Activity icon

Replied to Override Package Method (mewebstudio / Captcha)

I don't know if it's a typo, you called Captcha::src() which doesn't call create() function at all. I think your binding is right. Another small flaws is in your binding, Mews\Captcha\CaptchaServiceProvider::class, is not necessary as its already override by your custom class, but it will not affect the result anyway.

May
26
6 days ago
Activity icon

Replied to Route Problem

Thanks. Tests is necessary but i want a general small command for it, and also can put it into tests. You know, we have some old bad repository, without enough people writing missed api tests, and some routes file have many endpoints. So just a small code in this bad reality. I already written the command, but want to have a good name.

Activity icon

Replied to Route Problem

I mean it will never be hit, so its a coding problem. I just want to write a command to detect this kind of problem for our apps for some careless developers but want to have a name for it :)

Activity icon

Started a new Conversation Route Problem

here is a simple example:

Route::get('/post/{id}', '[email protected]');

// ...

Route::get('/post/new', '[email protected]');

if we write routes in this order, the /post/new will always be recognized as first route pattern by Laravel route resolver. The solution is pretty simple, we can change the order or add where condition behind post/{id} route.

My question is: How should we call this problem? "route conflict" seems too broaden to define the problem. Does the problem have a name or doesn't it even deserve a specific name?

Apr
22
1 month ago
Activity icon

Started a new Conversation Laravel+VSCode Users, What Are Your Recommended Extensions And Configs For VSCode?

Now I'm working from home and want to try VSCode rather than mega powerful PHPStorm. However I feel struggling, and main issues are on code intellisense and navigation (jump to definition, find usage of function/class), error check etc, especially for docker environment.

I need your help, to help me build a decent VSCode to use Laravel. Thanks!

Apr
14
1 month ago
Activity icon

Replied to Validate Ignore Not Working

seems like you forgot a comma after email

'users.email' => 'required | email | unique:users,email,' . $id
Apr
01
2 months ago
Activity icon

Awarded Best Reply on Unique With Validator


[
            'field1' => [Rule::unique('table1')->where(function ($query) use ($request) {
                return $query->where('col2', $request->input('field2'));
            }),]
];

like this?

Mar
04
2 months ago
Activity icon

Awarded Best Reply on HELP,TO MAKE IT WORK.

for queries, actually you have these db operations:

  • create 1 Order record;
  • create n OrderedProduction records;
  • update n Product records (the total_sold field);

I think they are all inevitable, only place to reduce queries is to do mass create or update for n records. However, I don't like this, because if you want to have model observers for OrderedProduction / Product to trigger some side processes, mass creation/update seems doesn't trigger model event.

So talking about your concern of atomicity, I think there are two suggestions:

  1. Use DB::transaction, wrap all the db operation into the transaction.

  2. (optional) move orderedProductSave() function to other place. you can add a service layer (like OrderService) to write business logic, and called from your OrderController. It's better for testing and maintenance. Let Controller be a pure Request handling entry. It's optional, as if your project is straight forward, put logic into controller is still acceptable.

Activity icon

Replied to HELP,TO MAKE IT WORK.

For moving orderedProductSave(), Its optional and not heavily related to your concerns. And not just for orderedProductSave(), I actually mean the whole save billing process. like this:

class OrderController extends Controller
{

    public function index()
    {
        $orders = QueryBuilder::for(Order::class)
            ->allowedFilters(['consumer_id'])
            ->allowedSorts('id')
            ->latest()
            ->get();

        return OrderCollection::collection(Order::paginate(20));
    }
    public function store(Request $request, OrderService $orderService)
    {
	$result = $orderService->checkout($request->all());

        return json_encode($request->amount);
    }

I just thought its better to make controller only to handle requests and call logic function from a separated layer (Service or Repository). It's not a MUST though.

Mar
03
2 months ago
Activity icon

Replied to Unique With Validator


[
            'field1' => [Rule::unique('table1')->where(function ($query) use ($request) {
                return $query->where('col2', $request->input('field2'));
            }),]
];

like this?

Activity icon

Replied to HELP,TO MAKE IT WORK.

for queries, actually you have these db operations:

  • create 1 Order record;
  • create n OrderedProduction records;
  • update n Product records (the total_sold field);

I think they are all inevitable, only place to reduce queries is to do mass create or update for n records. However, I don't like this, because if you want to have model observers for OrderedProduction / Product to trigger some side processes, mass creation/update seems doesn't trigger model event.

So talking about your concern of atomicity, I think there are two suggestions:

  1. Use DB::transaction, wrap all the db operation into the transaction.

  2. (optional) move orderedProductSave() function to other place. you can add a service layer (like OrderService) to write business logic, and called from your OrderController. It's better for testing and maintenance. Let Controller be a pure Request handling entry. It's optional, as if your project is straight forward, put logic into controller is still acceptable.

Feb
26
3 months ago
Activity icon

Replied to Why Horizon Save Failed Jobs To Redis?

Thanks for the explanation, making me feel more clear about that. So can I say Horizon just records failed jobs for statistics reason as They are not the place to know current status of failed jobs and handle them (e.g: artisan queue:work retry all, flush, etc command does not affect horizon redis data)?

Feb
25
3 months ago
Activity icon

Replied to Why Horizon Save Failed Jobs To Redis?

yes, it's definitely the right DB. And I just found something strange:

some failed jobs are recorded in the database (can be found in horizon too.), but most are not in db. When I tried to run php artisan queue:retry all, based on console output, only the ones in db brought into queue again.

Activity icon

Replied to Why Horizon Save Failed Jobs To Redis?

Thanks for help. I tried to clear the config cache manually, and everytime we do release we run cache:clear, config:clear and restart horizon as well. But the failed jobs always stored in redis's horizon:<failed_job_id> keys. Don't know why.

Activity icon

Started a new Conversation Why Horizon Save Failed Jobs To Redis?

Horizon version: v2.2.2

Issues:

I set in config/queue.php to use MYSQL to store failed jobs:

    'failed'      => [
        'database' => env('DB_CONNECTION', 'mysql'),
        'table'    => 'failed_jobs',
    ],

in .env DB_CONNECTION=mysql.

but horizon still save all faield jobs in redis instead. and failed_jobs table has no records.

Why is it working like this? How can I setup to let failed jobs to be stored in db?

Dec
09
5 months ago
Activity icon

Replied to Using External API To Create Record Directly But DRY Way

You can:

  • fetch the data from external api
  • build a request instance $req manually
  • call another controller's method using return app('App\Http\Controllers\Html\MovieController')->store($req);.

But I won't recommend this approach. I'd rather write store function's main logic in a extra layer such as repository or service, then for both Controllers, call this service's method.

Activity icon

Replied to Using Passport, Personal Access Token Expiration Behaviour?

Thanks! That make sense and seems like the function personalAccessTokensExpireIn was only added above 7.0 version.

I tried to change the expire_at use Passport::personalAccessTokensExpireIn(now()->addSecond(5))and confirmed that the expired_at in outh_access_tokens table are also set after 5 seconds from now. So this field in db is also make sense.