luddinus

luddinus

Member Since 4 Years Ago

Experience Points
24,700
Total
Experience

300 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
18
Lessons
Completed
Best Reply Awards
13
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 5
24,700 XP
19 Mar
6 months ago

luddinus left a reply on Two Laravel Projects, API And Front (Web). How To "login" The User?

And what about to "save" the API users to use in FRONT pages (protected)?

I want to use Blade pages, and make a middleware to protect the views (if the user is logged, go, if not, redirect to the login page for example).

The idea I have in mind is to save in database the users that are logged via API, that way I could use the middleware mentioned before in an easy way.

18 Mar
6 months ago

luddinus left a reply on Two Laravel Projects, API And Front (Web). How To "login" The User?

@martinbean Hey, thanks for the answer.

Actually I handle the API via jwt, no need for me to use Passport, that's not my question.

I want to split my project because I want to handle the API (backend) and some partner to focus only in the front-end, but using Laravel/Blade.

So I think, my main question is: Is it Guzzle a good option to make requests to the API?

17 Mar
6 months ago

luddinus started a new conversation Two Laravel Projects, API And Front (Web). How To "login" The User?

Hi.

I'm making an API, and I will use laravel for that. No problemo here.

I want to do TWO completely separate projects. I want to use simple blade pages in the front.

The main problem in my mind:

  • How to "login" a user?

I would have an endpoint like domain.com/api/auth and when I login successfuly, a token will be return from the API (maybe some additional info like user name etc.)

The code in the FRONT project

// LoginController
public function store()
{
    // guzzle?
    $response = $http->post('https://domain.com/api/auth', [
        'email' => '[email protected]',
        'password' => 'secret'
    ]);

    // $response ---> ['token' => '...', 'user' => ['name' => '...', 'email' => '...']];

    // successfull
    // save the token in my DB? (Database of the Front End project, only to save the login users for example?)

    return redirect('dashboard');
}

Then I guess I would only have to do the requests with the saved token to the API

// ProfileController

public function update()
{
    // ...
    $response = $http->put('https://domain.com/api/me', [
        'token' => 'Saved-token-from-the-db',
        'some_data' => 'to update the profile'
    ]);

    return back();
}

Is this a good way? Any ideas?

Thanks!

01 Mar
6 months ago

luddinus left a reply on Domain Driver Design, Directory Help

@BOBBYBOUWMANN - @bobbybouwmann Thanks.

Now I'm having asking my self what about "Actions". Should be the action classes cares about the validation, or I would have to "presuppose" that always when I run that actions the data is validated?

I was thinking to "extend" the Actions to FormRequest class, because of the validation helpers (and authorization), but I have the same problem with the other question. A Request that not belongs to the Domain directory.

On the other hand, I "know" that a special validation rule should be placed in Domain/Rules directory... (or similar)

28 Feb
6 months ago

luddinus started a new conversation Domain Driver Design, Directory Help

Hi.

I'm trying to follow this pattern, based a little bit on this project: https://github.com/spatie/attended.io/tree/master/app

This is my directory structure (more or less)

app
---...
---Domain
------User
---------Actions
------------UpdatePasswordAction.php
---------Models
------------User.php
------------Guest.php
---Http
------Controllers
---------Api
------------UsersController.php
-------------...
------Resources?
---------...

I want to make an api using Laravel Resources.

By default Laravel saves the Resources (via artisan) in the Http/Resources directory. Is it "more correct", in this case (UserListResource), to save in Domain/User/Resources directory? Or resources "belong" to Http?

At this time I think it fits better in Http/Resources directory because it's and "entry" point to the app.

Suggestions welcome!

02 Mar
1 year ago

luddinus left a reply on How Can I Get Rid Of N+1 Problem

How do you use those variables in your views?

22 Feb
1 year ago

luddinus started a new conversation Refactor A Lot Of Conditionals

Hi.

How would yo refactor this?

(User wants to apply to an offer)

// the code is in a Controller at the moment...

public function store($offerId)
{
   // validate the request etc.

   $offer = Offer::find($offerId);

   $errors = [];
   if ($offer->hasExpired()) {
      $errors[] = 'offer_expired';
   }

   if ($offer->isNotVerified()){
      $errors[] = 'offer_not_verified';
   }


   // if... if...

   if (count($errors)) {
      throw new CantApplyException($user, $offer, $errors);
   }

   return view('some view');

}
04 Jan
1 year ago

luddinus started a new conversation Naming Api Endpoints When Two "Entities" Are Envolved.

Hi,

I pick "tips" channel but I'm don't know if it is the correct. Anyway:

I have users and offers, and users can apply to job offers.

How would you name the api?

POST api/users/{user_id}/offers/{offer_id}/apply
POST api/offers/{offer_id}/apply/{user_id}
...
POST api/offers/{offer_id}/apply // pass the user_id in request body { user_id: 1 }

I'm using the first one but it seems a little awkard to me.

Thx!

22 Dec
1 year ago

luddinus left a reply on Issue When The SQL Query Is Slower Than Multiple Requests

Thanks for the response. I will try with cookie/session approach.

20 Dec
1 year ago

luddinus started a new conversation Issue When The SQL Query Is Slower Than Multiple Requests

Hi.

I have a page where an user can upload some photos.

Imagine that the limit is ten photos per user. I use dropzone to upload multiple photos, and it runs one request per photo upload.

The problem is that when I check the number of the photos inthe request, when the next request "starts", sometimes the query has not finished, so the user "sometimes" can upload more than ten photos. (I know I could do some front-end validation, but does not solve my problem.

// PhotoController
public function store()
{
   // check...
   if (request()->user()->countPhotos() >= 10)
   {
      return response()->json([
         'message' => 'You cannot upload more than 10 photos'
      ], 403);
   }

   // upload the photo...
}

What can I do to solve this?

11 Aug
2 years ago

luddinus left a reply on Am I Abstracting Too Much?

Well, I realize this was a good example of "premature" abstraction.

08 Aug
2 years ago

luddinus left a reply on Redis Configuration On Production

@devsrv Yep, I know how to install,

what I want is a "good" config file on production, because the redis default configuration It's ok for development.

07 Aug
2 years ago

luddinus started a new conversation Redis Configuration On Production

Hi everybody.

I want to switch the session driver from file to redis.

I have an ubuntu machine on AWS, and got redis installed. I installed predis/predis package too.

I'm overwhelming with too many information, I'm not asking how to use redis (I guess I have too change the session driver in environment file and that's all). I'm asking for a "good" configuration of redis in ubuntu.

Also, noob question I guess, but when I start redis-server on production server, redis is active, but when I close that tab, redis is down.

Anyway, need some light in configuration.

Thanks.

12 May
2 years ago

luddinus left a reply on Improve Collection!

@al0mie "each" method does not return anything... I'm practicing with collections and I think there should be a better way.

luddinus started a new conversation Improve Collection!

Hi,

How can I refactor this code? I want to iterate some fields, check if a method exists and then call it, here is the code:

$someCollection->filter(function ($value, $attribute) {
   // Imagine "getClassName" is very "expensive" method
   return class_exists($this->getClassName($attribute));
})->map(function ($value, $attribute) {
   // getClassName method again...
   return app($this->getClassName($attribute));
});

Any ideas?

Thanks!

06 May
2 years ago

luddinus left a reply on Database Schema Store Location

Well, when yo do $shop->city, you will get the City model (or null), not the city's name, so you will have to do $shop->city->name.

I would do this:

class City extends Model
{
   // ...
   public function presentLocation()
   {
       return "{$this->name}, $this->country->name";
   }
}

So in your view you could do

$city->presentLocation()

or the same but in the Shop Model

luddinus left a reply on Custom Accessor Vs Normal Method On The Model?

No I guess, but the "method" approach looks more natural.

IMO, the "attribute" approach is for overriding attributes from existing database fields. (e.g by default created_at and updated_at attributes are Carbon instances)

05 May
2 years ago

luddinus left a reply on What Are You Missing?

When I visit the profile and I saw my recent replies, it would be nice a direct link to the reply.

luddinus left a reply on Laravel - Replace Null With Empty Array When No Relation Is Found

I would create a "NullWeb" model that extends "Web" model, maybe it's useful in your case.

return $this->hasOne(Web::class)
   ->withDefault(function () {
      return new NullWeb;
   });
09 Apr
2 years ago

luddinus left a reply on Best Practice For Handling "active" Menu Item In L5

This is what I use (keep it simple)

app/helpers.php

function active_if($routeNames)
{
    $routeNames = (array) $routeNames;

    foreach ($routeNames as $routeName) {
        if (Route::is($routeName)) {
            return ' class="active"';
        }
    }

    return '';
}
    

some view

<li{!! active_if('login') !!}><a href="{{ route('login') }}">Login</a></li>
06 Apr
2 years ago

luddinus left a reply on Directive With Template?

@willvincent Thx, I see the vuejs2 series, they are great but I'm still learning. I'll take a look to the vue1 series as well.

Anyway, I thought in the case you'are saying but that way, how can I add button attributes in an "easy" way? I mean, whatever I want instead of declaring "props" in the component.

e.g

"easy way"
<button class="btn btn-default"
   some-other-attribute="some-value"
   spinner-button>Save
</button>

luddinus started a new conversation Directive With Template?

Hi, I used to use Angular, so maybe what I want is not possible or I don't know yet.

I want to build a custom "directive" that appends (or prepends) some Html to the element given (a button with a spinner).

e.g:

<button v-button-spinner="saving">Save</button>

Two things I want.

  1. Add the spinner inside the "button" tag, something like this:
<template>
   <span>
      <i class="fa fa-spin fa-spinner" v-if="saving"></i><slot></slot>
   </span>
</template>
  1. Toggle the "disabled" attribute into the button (two way bind with "saving")

Any ideas? Probably is not that hard, but I think I still "poisoned" by Angular.

Thx.

05 Mar
2 years ago

luddinus left a reply on Vuejs Instance In Master.blade And Other Instance In Login Page?

@alenabdula My case is different I think.

I have a "master" app that will have some behaviours in all the pages (all the pages that extend the master layout).

In other pages (like login) I want to "run" two apps in the same page, the "master" vue instance and the "login" vue instance.

I know that I could do the master "app" as a component and then include into the "login" vue app, but that would require to load the master app in other pages that maybe don't have any special behaviours.

Hope I explain...

04 Mar
2 years ago

luddinus started a new conversation Vuejs Instance In Master.blade And Other Instance In Login Page?

Hi,

I'm relative new to vuejs world.

I have a master.blade template, where I load master.js script.

<html>
   ...
   <body>
      <div id="master">
         <h1>@{{ message }}</h1>

         @yield('content')
      </div>
      
      <script src="/js/master.js'></script>
      @stack('scripts')
   </body>
</html>

master.js (nothing relevant from now)

var app = new Vue({
   el: '#master',

   data: {
      message: 'Hello World!',
   }
});

Now I have a login page that extends the master page (which already "loads" a Vue app), and I want to test some button

login.blade.php

@extends('master')

@section('content')
<button @click="testClick">Click me</button>
@stop

@push('scripts')
// HERE IS MY QUESTION
// get the master.blade.php app and "add" the testClick function??
@endpush

Where do I implement the "testClick" function?

Thx

10 Nov
2 years ago

luddinus left a reply on Use Your Helper Methods Without The Boring Namespace Stuff

Mmm, the package seems too "magic", in those cases I prefer to make a Presenter class

class BookPresenter
{
   protected $book;

   public function __construct(Book $book)
   {
      $this->book = $book;
   }

   public function price()
   {
      // return whatever format
   }
}
class Book extends Model
{
   // ...

   public function present()
   {
      return new BookPresenter($this);
   }
}
<ul>
   <li>{{ $book->title }} - {{ $book->present()->price() }}</li>
</ul>
02 Nov
2 years ago

luddinus left a reply on Optimizing Laravel Query To Get Required Data

You could try something like this

SomeModel::with(['somerelationkey' => function ($relationModelQuery) {
   $relationModelQuery->select('id', 'field1', 'field2');
}]);
28 Oct
2 years ago

luddinus left a reply on Correct Way To Use Config Files

Don't forget to implement an interface.

27 Oct
2 years ago

luddinus left a reply on Useful Blade Directives

I don't have it but some directive for font-awesome icons, something like:

// second argument optional
@fa('users', '2x')

// equals to
<i class="fa fa-users fa-2x"></i>
20 Oct
2 years ago

luddinus left a reply on Why Does Laravel Symlink Storage?

I'm curious too

19 Oct
2 years ago

luddinus left a reply on Issues With Mailgun And Office365/Outlook.com

@otepas18 I only send "transactional" emails (don't know how to say). I mean, an user registers in my site and I send a confirmation email. That email goes to Spam. Not all the users, and not always, that's frustrating.

I don't have the "unsubscribe" link because is not a newsletter and we have the info of the company in all the emails...

Anyways, thank you for your response.

luddinus left a reply on Issues With Mailgun And Office365/Outlook.com

The problem is that mandrill is not free.

How do I know that I won't have these errors in Mandrill?

18 Oct
2 years ago

luddinus left a reply on Issues With Mailgun And Office365/Outlook.com

@gsc89 I have the same problem.

I think the only think I can do is to "add" plain html emails but I'm not sure if is that something that is going to work...

What did you do?

luddinus left a reply on Issues With Mailgun And Office365/Outlook.com

Same issue here, don't know what to do...

maybe change Mailgun to SparkPost?

05 Oct
2 years ago

luddinus left a reply on Having Trouble Translating Auth Validation

Probably your auth POST request is not containing the locale in the url, so it gets the default app.locale (french in your case)

03 Oct
2 years ago

luddinus left a reply on Pass Message Body From Form To Email? Email Working, But No Message Body :(

The code looks good, you will get $data['body'] in your template...

luddinus left a reply on Socialite - Facebook User_photos Scope

Well, my mistake.

The "scopes" function must be "called" BEFORE the login (of course...), so this works:

Socialite::driver('facebook')->scopes(['user_photos'])->redirect();

luddinus started a new conversation Socialite - Facebook User_photos Scope

Hi,

I'm trying to login with facebook with some scopes but those scopes are never requested. Here is my code:

// facebook redirect controller
Socialite::driver('facebook')->fields([
   'email',
  // etc.
])->scopes(['user_photos', 'publish_actions']);

The problem I guess, is that the url generated is not adding the scopes params correctly:

// url generated
&scope=email&response_type=code
// desired url params
&scope=email,user_photos&response_type=code

What am I doing wrong? (I already have the user_photos permission reviewed by facebook)

Thx.

22 Sep
3 years ago

luddinus left a reply on Regex Validation Messages

@bugsysha Thx, I think it will do the trick.

luddinus left a reply on Regex Validation Messages

@bugsysha Let me explain better:

Imagine I cannot enter two dots and I cannot enter numbers, the regex is only one, but the error messages would be more than one for that regexp

e.g

entered: "ludd..inus" --> error: You cannot enter two dots. entered: "luddinus99" --> error: You cannot enter numbers.

That's what I want.

luddinus left a reply on Regex Validation Messages

@bugsysha I'm not asking for the regex, I'm asking if there is a way to show specific error messages depending on the input.

21 Sep
3 years ago

luddinus started a new conversation Regex Validation Messages

Hi,

Imagine I have some regex that checks the username. It accepts only letters and one space or one dot.

e.g: "luddinus", "ludd.inus", "ludd inus".

Suppose I enter a name with two dots, so I would like the message to be "You can enter only one dot."

In a FormRequest class, I can set the messages, but only for the regex.

public function rules()
{
   return [
      'username' => 'required|regex:/someregexhere/';
   ];
}

public function messages()
{
   return [
      'username.regex' => 'Username is not valid' // Always be this message...
   ];
}

Is there an easy way to achieve this?

Thx.

19 Sep
3 years ago

luddinus started a new conversation Which Files Change When "composer Update"?

Hi,

I'm thinking of run "composer update" in production server (thug life).

Which files are goind to change? I know vendor directory for sure, but any other files? composer.json? bootstrap/services.php?

I need to know to make a backup for those files...

Thx.

12 Sep
3 years ago
11 Sep
3 years ago

luddinus left a reply on Asynchronously Update A Model From A 'saved' Event

I had a similar issue and I ended using DB::table('table')->update(...)

04 Sep
3 years ago

luddinus left a reply on How Are Models Called Statically

@vkronlein I know about the Repository pattern, but I think it is one of the most overrated patterns. IMO you are abstracting too much.

I don't see the point to have "create", "update", "delete" method that do almost the same of Eloquent. Furthermore, that repository accepts only Eloquent models...no sense.