Cobs

Cobs

Member Since 7 Months Ago

Experience Points 2,620
Experience Level 1

2,380 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 4
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

17 Jun
1 week ago

Cobs left a reply on How To Validate My Form Field Individually In Laravel

The 'bail' rule will make the validation stop running after the first faillure

https://laravel.com/docs/5.8/validation#quick-writing-the-validation-logic

$request->validate([
    'title' => 'bail|required|unique:posts|max:255',
    'body' => 'required',
]);

Cobs left a reply on How To Validate My Form Field Individually In Laravel

For complex validation process, i suggest to use a FormRequest : https://laravel.com/docs/5.8/validation

Can you tell what your laravel version is and more details about your validation rules ?

13 Jun
1 week ago

Cobs left a reply on What Should To Learn To Be A Laravel Pro

Well, imho, you need to learn what you need to use.

if you try to improve the loading time of your assets, you definitively should have a look to laravel mix. but maybe you want to optimize the response time instead, so you need to look at the cache system, or maybe the job queue.

you're getting pro by finding/learning solutions to problems, not really by mastering the tools laravel provides you.

Identify problems and find how laravel helps you to solve them. my suggested "need to know" for laravel is :

Eloquent obviously. especially relation's eager and lazy loading. Observers & Events Validation with FormRequests Testing, testing everywhere

27 May
4 weeks ago

Cobs left a reply on How To Match Word From Beginning Until A Space In A Query To Get Result?

i suppose you can do this by exploding your string and use a WHERE OR block.


$keywords = explode(' ', 'tesco store');
$query->where(function($q) use($keywords){
    foreach($keywords as $keyword)
    {
        $q->orWhere('keyword','LIKE',$keyword);
    }
});
17 May
1 month ago

Cobs left a reply on How To Setup HTTPS With Laravel Homestead On Ubuntu 18.10

There is a lot to explain from "Where do i get a certificate" to "How my web server use them" and i won't be able to explain everything. If you're a bit lost, let's make things short: use certbot (https://certbot.eff.org/)

Certbot is a quick and dirty way to setup a SSL certification with Let's Encrypt, but it a pretty good tool to start with.

Cobs left a reply on Change Laravel En Folder For Translations

you can change the Localization directory with App::setLocale($locale);

look at this : https://laravel.com/docs/5.8/localization#configuring-the-locale

28 Mar
2 months ago

Cobs left a reply on Laravel Views Or Vue Component

All depends on your UX design. You can put everything as vue component or have a hybrid approach. I don't know the best approach but i know there are things to avoid, like insert server-side generated html into your vue DOM.

25 Mar
3 months ago

Cobs left a reply on Laravel Youtube

I don't know any laravel specific ways request the Youtube API. You'll have to use Guzzle or Curl and have a look to the API documentation https://developers.google.com/youtube/v3/docs/videos

22 Mar
3 months ago

Cobs left a reply on Call To Undefined Method Illuminate\Database\Query\Builder::save()

Only eloquent models implement the save() method. query builder must use insert(), update() or updateOrInsert()

https://laravel.com/docs/5.8/queries#inserts

20 Mar
3 months ago

Cobs left a reply on VUE.js | Redirecting To Outside Website

vanilla js will be fine:

window.location = 'http://www.example.com'
14 Mar
3 months ago

Cobs left a reply on Sorting Based On Loaded Relationship

Eloquent load relationship datas with separate queries. I don't think you can sort your medias by a column in the episode table,without to join your tables by yourself.

Cobs left a reply on Debugging Exceptions

Maybe you should check your web server access Log to find out what is the url requested at the same timecode.

Cobs left a reply on Debugging Exceptions

the MethodNotAllowed Exception is thrown when a request match a route pattern, but do not match any route method (GET, POST, PUT, DELETE)

Cobs left a reply on How Can I Use Order By On Relationship?

Either

Use the Eloquent collection to sort

$modules = \App\Course::find($course->id)->modules->sortBy('sort');

add the order by instruction on the fly

$modules = \App\Course::with(['modules' => function ($query) {
        return $query->orderBy('sort');
    }])->find($course->id);
13 Mar
3 months ago

Cobs left a reply on How To Return Value Without The Column Name?

Since you only want one record in the roles table, use first() instead of get() in your query.

Cobs left a reply on How To Select Specific Columns And Get Related Relationships

you have to fetch the data first, then map the collection as needed.

$users = User::with('posts')->get();
$mapped = $users->map(function($user) {
    return ['name' => $user->name, 'posts' => $user->posts];
});

Cobs left a reply on How To Select Specific Columns And Get Related Relationships

using 'with' method on the result of the 'pluck' method makes no sense to me. What result do you expect.

12 Mar
3 months ago

Cobs left a reply on How Can I Make A Data Available To All Views

key is the name of the blade variable to assign, 'countCartItems' in your case. value is the value you want to put in.

11 Mar
3 months ago

Cobs left a reply on CORS Erro In Laravel Vue

Do what the browser tell you. add "x-csrf-token" to the list of allowed headers "Access-Control-Allow-Headers" in your middleware

08 Mar
3 months ago

Cobs left a reply on Why Should I Use 'storage:link"?

@karlm89 I'm pretty sure i don't want to deploy the public storage of my local environment to all production applications xD. Imagine a Gallery application. are you sure you want to push uploaded images ?

Cobs left a reply on Why Should I Use 'storage:link"?

It's easier to configure Http server to serve only one folder than put .htaccess everywhere. Also it's convenient for versioning tools, you usually don't want them to track files in the storage but you want to track everything else in the public folder.

Cobs left a reply on THE LARAVEL WAY Of Http Get Requests To External API

Testing requests aren't "real" requests sent by an http client. Laravel automaticaly build a SymfonyRequest and send it to HttpKernel of your application.

07 Mar
3 months ago

Cobs left a reply on Observer Not Firing

I can't spot any code issue. The autoloader cache maybe ?

Cobs left a reply on Who To Show The Union Of 2 Tables Query?

Can you tell what Requests and Events are, exactly ?

Cobs left a reply on Observer Not Firing

can you show the created method in ProjectObserver ?

06 Mar
3 months ago

Cobs left a reply on What's The Difference Between @yield And @include

@include juste copy/paste a partial to the main layout

@yield use the template Inheritance. Personnally, I use a lot the section's overriding so i highly prefer @yield over @include.

22 Feb
4 months ago

Cobs left a reply on Naming Routes

Not a bad practice at all. the naming convention laravel use for routes have this form "resource.method" https://laravel.com/docs/5.7/controllers#resource-controllers

Just be vigilent, different routes can have the same URI and you could end in the wrong route if you don't use the proper "_method" parameter.

Cobs left a reply on Style

You can only override an -important- property with another -important- property with a higher or equal weight.

Cobs left a reply on Number Of Foreign Key Occurrences In Faker Seeder

First of all, it's often a terrible idea to store computed values in the database. You will have to update all rows each time a dependancy is update. it will dramatically increase your number of queries and your code complexity.

Your question is "how can I fill the 'centers' column" You can't. I mean, you didn't created the Academy yet. how can you possibly guess how many centers there are.

Eloquent Models & Relations will provide you many ways to retrieve this number when needed and with a bit of cache managment, this will not cause any performance issue.

31 Jan
4 months ago

Cobs left a reply on Solution To Axios.post Cors Problem

yes, HandleCors won't do the trick alone, you still have to provide Access-Control-Request-Headers & Access-Control-Request-Method to your request.

29 Jan
4 months ago

Cobs left a reply on Collection WhereBetween Method Not Working

The method exists in the 5.7 branch https://github.com/laravel/framework/blob/5.7/src/Illuminate/Support/Collection.php

so it maybe it is something with your local environement or files. If you use composer you can remove your 'vendor/laravel/' directory and running 'composer install' to download a fresh library

16 Jan
5 months ago

Cobs left a reply on Show New And Old Attributes

@JLANZAS - > Do you know of $model->wasChanged('field') or to get all changes:

Eloquent Models have the getDirty() function for that. https://laravel.com/api/5.7/Illuminate/Database/Eloquent/Model.html#method_getDirty

15 Jan
5 months ago

Cobs left a reply on Triple Pivot Table

Maybe you should define one ( or multiple ) custom models to this intermediate table


class UserCompany extends Pivot
{
  protected $table = 'company_role_user';

  public function role()
  {
    $this->belongTo('App\Role','role_id')
  }
}

Your User's relation could be something like that

    public function companies()
    {
        return $this->belongsToMany('App\Company')->using('App\UserCompany');
    }

then, for exemple, you could retreive a role like this

$role = $user->companies[0]->pivot->role

I probably forgot something, but i know it's possible. i did it with laravel 5.4

10 Jan
5 months ago

Cobs left a reply on Location.href

try "window.location = url " instead of "location.href = url"

04 Jan
5 months ago

Cobs left a reply on Best Way To Track And Store Database Model Events

You can easily track CRUD events with the Eloquent model observers https://laravel.com/docs/5.7/eloquent#observers

I don't know any lib that would automaticaly record all the changes, but eloquents models have convenient methods to do so.

getDirty() returns the attributes that have been changed since last sync. getOriginal() returns the model's original attribute values before it was changed.

Have a look : https://laravel.com/api/5.7/Illuminate/Database/Eloquent/Model.html

Cobs left a reply on Where On Foreign Table In BelongsToMany Relation?

in a many to many relationship, you can reach the pivot table with wherePivot

return $this->belongsToMany(Game::class, 'game_users', 'user_id', 'game_id')->wherePivot('locked', true);
02 Jan
5 months ago

Cobs left a reply on Sort Collection By Two Conditions

the easiest solution is to let the database do the sorting.

$query->orderBy('top_user');
$query->orderBy('created_at');

it's a bit more tricky if you want to sort a Collection object. you have to write Closure to process a usort-like comparison

$collection->sort(function($a, $b) {
    if($a->top_user === $b->top_user)
    {
        if($a->created_at === $b->created_at) {
            return 0;
        }
        // I assume a 'created_at' is a Carbon Instance
        return  $a->created_at->isBefore($b->created_at) ? -1 : 1;
   } 
   return $a->top_user > $b->top_user ? -1 : 1;
});
26 Dec
6 months ago

Cobs left a reply on Laravel Match Against Paginate

Sure, just use a query builder instance from the model instead of DB::table

$query = MyModel::query();
...

Cobs left a reply on MorphToMany Custom Keys

isn't supposed to be a "morphedByMany" relation instead of "morphedToMany"

Cobs left a reply on Laravel Match Against Paginate

I did something like that once. didn't tried the pagination however.

DB::table('mytable')
->selectRaw('mytable.*')
->selectRaw('MATCH ('indexed_column') AGAINST (?) AS relevance', [$search_string])
->whereRaw('MATCH ('indexed_column') AGAINST (?)', [$search_string]);
});
24 Dec
6 months ago

Cobs left a reply on Convert MySQL Raw Query To Eloquent Statement

What do you mean "so that i can use relations" ? You must have a model instance to use a relationship.

Cobs left a reply on Array Validation

I used the foreach solution.

17 Nov
7 months ago

Cobs left a reply on Array Validation

@PALAK27 - laravel 5.4

13 Nov
7 months ago

Cobs started a new conversation Array Validation

hi guys, i'm getting stuck on validating an array item against multiple other value of this items.

My condition value is required only if criteria & type are equal to 1

$rule['conditions.*.value'] => [
    'required_if:conditions.*.type,1',
    'required_if:conditions.*.criteria,1'
]

but i can't find a way to make it works. i tried the complexe validation function "sometimes" but it don't help on array validation.