rafaelmsantos

rafaelmsantos

Junior Web Developer at Velcro Design

Member Since 4 Years Ago

Lourinhã

Experience Points
1,660
Total
Experience

3,340 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
14
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
1,660 XP
Jan
25
2 years ago
Activity icon

Started a new conversation Laravel 5.4 Failing On Php Artisan Migrate After Php Artisan Make:auth

Hi, I decided to test the new Laravel 5.4. So I started with the basic commands:

$ laravel new blog

$ php artisan make:auth

$ php artisan migrate

The last command returns an error, I will write it here:

[Illuminate\Database\QueryException]                                                         
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key  
   length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))   
[PDOException]                                                                               
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key  
   length is 767 bytes  

The database configuration on .env file is correct, since booth migrations and users table are created.

Any idea why is this failing?

Oct
14
3 years ago
Activity icon

Replied to How To Set A HasMany Relation Between 3 Tables?

Thats not it @tomi, but thanks for your help

Activity icon

Started a new conversation How To Set A HasMany Relation Between 3 Tables?

How to set a hasMany relation between 3 tables? Imagine the example:

I have users, teams, roles and finally to connect all, user_teams. A user could belong to multiple teams, and have a different role in each team. My user_teams table is represented like this:

user_id integer
team_id integer
role_id integer

And this is my 3 models so far:

class User extends Eloquent
{
    public $timestamps = false;
    protected $table = 'users';
    protected $fillable = ['name', 'email', 'password', 'locale', 'token', 'status', 'created', 'updated'];

    public function teams()
    {
        return $this->belongsToMany('Models\Team', 'user_teams', 'user_id', 'team_id');
    }
}

class Team extends Eloquent
{
    public $timestamps = false;
    protected $table = 'teams';
    protected $fillable = ['name', 'slug', 'type', 'created', 'updated'];

    public function users()
    {
        return $this->belongsToMany('Models\User', 'user_teams', 'team_id', 'user_id');
    }
}

class Team extends Eloquent
{
    public $timestamps = false;
    protected $table = 'teams';
    protected $fillable = ['name', 'slug', 'type', 'created', 'updated'];

    public function users()
    {
        return $this->belongsToMany('Models\User', 'teams_users', 'team_id', 'user_id');
    }
}

Any ideas on how to achieve this?

Oct
19
3 years ago
Activity icon

Replied to Extend Eloquent To Do Something Before Creating A New Record

I found this: https://bosnadev.com/2014/12/28/laravel-model-observers/ on saving model observer

I think that will do the trick, thanks for your help

Activity icon

Started a new conversation Extend Eloquent To Do Something Before Creating A New Record

Hi everyone,

I always use order column in almost any model I create, the problem is that in each save/create, I have to check what last order value is on the table, increment it by one and than create the new record with the new order value.

Is it possible to extend or override Eloquent method of creation? Could I use a Trait to achieve this?

Thanks in advance

Oct
02
4 years ago
Activity icon

Replied to How To Return Fields Name Instead Of Error Message With Validator? [HELP]

A little digging trough MessageBag class interface and I found something.

This made the trick for me:

$validator->errors()->keys()

Hope this helps someone with the same doubt.

Activity icon

Started a new conversation How To Return Fields Name Instead Of Error Message With Validator? [HELP]

I wanted to return only the field names instead of a full message when validation fails. I have this code now:

$validator = Validator::make($request->all(), [
    'code' => 'required|unique:locales|max:2',
    'name' => 'required',
]);
if($validator->fails()){
    return dd($validator->errors()->all());
}

and this returns

array:2 [
    0 => "The code field is required."
    1 => "The name field is required."
]

And I want to return only this:

array:2 [
    0 => "code"
    1 => "name"
]

Cheers.

Oct
01
4 years ago
Activity icon

Replied to Load DB Localization Settings On A Service Provider

Well, I've used the Eloquent Model on boot() method in the AppServiceProvider and it seems to have worked.

Activity icon

Started a new conversation Load DB Localization Settings On A Service Provider

Hi everyone,

I'm using this package from mcamara do deal with my website Localization. To load new languages the package requires it to be loaded on a ConfigServiceProvider, my problem is that I want to make this manageable trough the database and I don't know how to load DB on the service provider.

Any tips?

Jun
11
4 years ago
Activity icon

Replied to PHPStorm Theme

Let me know if you convert this to phpstorm @gwp ;)

May
04
4 years ago
Activity icon

Replied to Avoid VerifyCsrfToken Middleware In A Route

Yes, I'm using this wysiwyg jquery plugin, and I need a route to upload images. The problem is, the documentation is very low, and the plugin has only a minified version. I tried to dig in, and find a way to send csrf_token() function, but I couldn't find a way. My only way now, is switching to another plugin or avoid this middleware for this route only.

Activity icon

Started a new conversation Avoid VerifyCsrfToken Middleware In A Route

Hi, I have a post route

Route::post('/uploadimage', 'Admin\DashboardController@uploadImage');

I don't want this route to VerifyCsrfToken, I know this isn't secure, but I got authentication middlewares here, so, not much of a problem if I remove this in only this route. How can I achieve this?

Apr
30
4 years ago
Activity icon

Replied to Which Is The Best Practice To Associate A BelongsTo Relation Model Id Attribute?

I see, so it resumes to whether is best suited for this case or not. Thanks for your answers @pmall and @frezno.

Activity icon

Replied to Which Is The Best Practice To Associate A BelongsTo Relation Model Id Attribute?

So, first is more secure because it ensures that the element exists, but second is more readable. The second one is faster and uses less resources, or there's really no difference?

Activity icon

Started a new conversation Which Is The Best Practice To Associate A BelongsTo Relation Model Id Attribute?

Hello everyone,

currently on a project of mine, I had this Model Ad that has many belongsTo relatioships. For example, ads table, has an attribute for location_id, status_id, eye_color_id, etc.

When saving a new Ad, I'm using this code:

$ad->user()->associate(User::find(Auth::user()->id));
$ad->location()->associate(Location::find($request->input('location')));
$ad->eye()->associate(Eye::find($request->input('eye_id')));
$ad->skin()->associate(Skin::find($request->input('skin_id')));
$ad->hair()->associate(Hair::find($request->input('hair_id')));
$ad->country()->associate(Country::find($request->input('country_id')));

but I could simply use:

$ad->user_id = Auth::user()->id;
$ad->location_id = $request->input('location');
$ad->eye_color_id = $request->input('eye_id');

I was wondering, which is a better practice method or better approach? (sorry for my spelling errors, non-native speaker here)

Apr
28
4 years ago
Activity icon

Replied to WhereHas Gets Me An Undefined Variable Error

Thanks guys, you're questions really helped me a lot. I'll accept @JarekTkaczyk answer only for the link with explanation, because booth answers were really helpfull.

Activity icon

Started a new conversation WhereHas Gets Me An Undefined Variable Error

Hello everyone, I'm using the following bit of code to retrieve all "Ads" with a "Category" with certain id's.

$selected_categories = Session::get('selected_categories');
$ads = Ad::whereHas('categories', function($query){
    $query->whereIn('id', $selected_categories);
})->get();

It gives me error on the 3rd line, saying $selected_categories is not defined, I've tried:

$ads = Ad::whereHas('categories', function($query, $selected_categories){

but it still fails. It throws:

Missing argument 2 for App\Http\Controllers\FilterController::App\Http\Controllers\{closure}()

Since I'm using Sessions, I could use the Session variable, but thats not what I'm looking for. I'm expecting this to happen in places where I'll not have a Session variable to do the trick, so, how do I pass a variable here?

Apr
23
4 years ago
Activity icon

Replied to Resources Folder Inside App/ Folder ?

I guess you were right. I just had to correct the paths in config/view.php

This is what I have now:

'paths' => [
    realpath(base_path('app/Resources/views'))
],

Thanks Ruffles

Apr
22
4 years ago
Activity icon

Started a new conversation Resources Folder Inside App/ Folder ?

Hello everyone. I'm can't get used to this structure using Resources folder outside of app/. Is there a way to use it inside, without getting in trouble?

Thanks in advance.

Mar
27
4 years ago
Activity icon

Replied to Laravel 5 Location Of Your App Mini Project

If I understand you correctly, you mean little modules for your application, if thats what you want, look at this code: https://github.com/caffeinated/modules