wivaku

wivaku

Member Since 1 Year Ago

Experience Points
260
Total
Experience

4,740 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
0
Lessons
Completed
Best Reply Awards
0
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 1
260 XP
21 Apr
5 months ago

wivaku left a reply on Skip Auth When Using Certain Route Prefixes

And the other solution. Here I let the controller check the request's route prefix to decide if auth middleware is needed.

Http/Controllers/MapController.php

public function __construct() {
  if (request()->route()->getPrefix() !== '/share') $this->middleware('auth');
}

public function timelineDate($date) {
    ...
}

routes/web.php

// regular route (login required)
Route::get('timeline/{date}', '[email protected]')
    ->name('timeline.date')

// route group for shared versions of the route
// middleware: make sure they are correctly signed
// calling regular version of the method (timelineDate)
Route::prefix('share')->name('share.')->middleware(['signed'])->group(function() {

    Route::get('timeline/{date}', '[email protected]')
    ->name('timeline.date');

});

// in blade, e.g.: 
// app('url')->signedRoute('share.timeline.date',['2019-04-21']);
// http://.../share/timeline/2019-04-21?signature=xyz --> share.timeline.date --> [email protected]

wivaku left a reply on Skip Auth When Using Certain Route Prefixes

This is how I solved it now. But interested to hear if this is the recommended way.

Http/Controllers/MapController.php

public function __construct() {
    $this->middleware('auth')->except(['shareTimelineDate']);
}

public function shareTimelineDate($date) {
    return $this->timelineDate($dateRange);
}

public function timelineDate($date) {
    ...
}

routes/web.php

// regular route (login required)
Route::get('timeline/{date}', '[email protected]')
    ->name('timeline.date')

// route group for shared versions of the route
// middleware: make sure they are correctly signed
// calling specific "share" version of the method (and in controller: add that one to the middleware except)
Route::prefix('share')->name('share.')->middleware(['signed'])->group(function() {

    Route::get('timeline/{date}', '[email protected]')
    ->name('timeline.date');

});

// in blade, e.g.: 
// app('url')->signedRoute('share.timeline.date',['2019-04-21']);
// http://.../share/timeline/2019-04-21?signature=xyz --> share.timeline.date --> [email protected]

wivaku left a reply on Skip Auth When Using Certain Route Prefixes

Do you have suggestions of what should be changed?

Both the logged in + guest versions (should) use the same controller (with the default construct that has auth middleware enabled). The route group doesn't have middleware specified.

E.g. remove the middleware from the construct and explicitly create auth and non-auth version of the route groups? I would prefer to have the controller protected by default, and specify exceptions for certain route prefixes.

wivaku started a new conversation Skip Auth When Using Certain Route Prefixes

Pretty new to Laravel (5.8).

Is it possible to disable authentication for specific (signed) routes / route groups? The use case: create+use share links that don't require login.

I would like to have signed routes with prefix (e.g. "share/order/1234?signature=xyz") that can be accessed without logging in.

My controller has __construct() with $this->middleware('auth');

And I grouped the share routes:


// regular route (login required)
Route::get('timeline/{date}', '[email protected]')
    ->name('timeline.date')

...

// route group for shared versions of the route --- should not require login
Route::prefix('share')->name('share.')->group(function() {
    // http://.../share/timeline/2019-04-21?signature=xyz --> share.timeline.date
    Route::get('timeline/{date}', '[email protected]')
    ->name('timeline.date');

    ...
});

Suggestions on how to achieve this? I looked at adding except to the controller construct, but was not sure what to put there. Was looking if I can / need to modify the route group.

Update: expanded the routes details with more complete example of current situation.

29 Jul
1 year ago

wivaku left a reply on Get "books With At Least 3 Reviews"

Mmm, has works, having does not work.

Documentation seems to suggest having is used in combination with groupBy. https://laravel.com/docs/5.6/queries#ordering-grouping-limit-and-offset

Found the tweak using has here: https://laracasts.com/discuss/channels/laravel/withcount-where-clause

But thanks @crnkovic for the replies and pointing me in the right direction!

wivaku left a reply on Get "books With At Least 3 Reviews"

Thanks! I looked at the documentation, but completely missed withCount. Exactly what I needed.

BTW. I had to slightly tweak it.

$books = Book::withCount('reviews')->has('reviews','>=',3)->get();
// doing where('activities_count',...) gave SQL error about unknown column

foreach ($books as $book) {
    echo $book->title .": ". $book->reviews_count ."\n";
    // at this stage it is fine to use reviews_count
}

wivaku left a reply on Get "books With At Least 3 Reviews"

I coded the models and the relationship. E.g. Book::find(1)->reviews()->get()

wivaku started a new conversation Get "books With At Least 3 Reviews"

I have Book and Review model and a hasMany relationship between books and reviews. How do I get all the books that have at least 3 reviews?

11 Feb
1 year ago

wivaku started a new conversation Suggestions For Structuring Service That Performs Business Rules On Database Records?

New to Laravel. Loving it! Limited OOP experience. Hope the following is not too broad of a question!

I load TV show metadata (series and episodes, e.g. title, description, cast), and perform checks on the metadata using business rules.

Previously (non-Laravel) I simply had a Business rules class, which contained a list of methods. I would have a method to load the metadata and then a method that would execute each of the validation methods. The result would be an array of results.

Trying to convert that to the Laravel way of working. Not sure what that would look like. I have models for Series, Episode, Rule and these load the data from the database. I have API endpoints that handle requests to view the metadata. Missing: handling requests to perform the business rules and return/display the results.

How to create the Business Rules functionality the Laravel way? I am confused about where + how to create Service Container, Service Provider, etc. Trying to follow + apply the (very readable) info https://m.dotdev.co/understanding-laravel-service-container-bd488ca05280 Not sure what it would look like for my case (and not sure if it is still the same for v5.5/5.6). And: not sure if/how I can/should use custom Validators for this and combine them with the above. (https://laravel.com/docs/5.5/validation#custom-validation-rules) Often it is not clear to me what to use for which and where to put the files.

Details: I have metadata for TV show series and episodes (sequence number, title, description, etc.). Models: Series and Episode. These are loaded from the database. I want to create an app that when asked for (API, or console), checks the metadata for a series. It loads the Series from the database and the Episodes for that Series. That part is done and clear. I also have a list of business rules in a database (model Rule: label, validation method). These can be simple ones that are probably covered by existing Laravel validators (check if title is empty), but can also be complex: "episode title is repeated in that season", or "episode index number is non-sequential [skipping or duplicated]"). The outcome of the validation is true/false + the current value (e.g. for rule: checkImageDimensions the currentValue could be 1024x768 instead of the normal value: the URL of the image). I want to return a list of rules that failed. They contain details from the metadata item (item ID, title) combined with rules results (rule ID, rule label, current value according to rule).

Thanks in advance for pointing me in the right direction!