Corban

Corban

Member Since 1 Year Ago

Experience Points 15,520
Experience Level 4

4,480 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 111
Lessons
Completed
Best Reply Awards 7
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.

10 May
1 year ago

Corban left a reply on WhereIn Only Matching Values With Two Units, Not Three

@lanatel yep, that works!

I still don't understand why it stopped working but at least it's back. Thanks.

Corban left a reply on WhereIn Only Matching Values With Two Units, Not Three

Nope, in fact that breaks it even more, it stops returning the ids below 100.

And why an ->all() after ->get(), I haven't seen both together, I thought they shouldn't go that way.

Corban started a new conversation WhereIn Only Matching Values With Two Units, Not Three

Hello everyone, I have a really strange problem that I don't seem to understand, since it has been working properly until now.

I need to fetch certain values from a select group, in order to make that I first retrieve the needed ids:

$first = Users::select('id')->where('column', condition1)->where('column2', condition2)->get();

Then I just use them in the next query:

$query = Model::where('column', condition1)->whereIn('user_id', $first)->orderBy('created_at')->get();

It has been working properly until now, but today I have noticed that any id above 100 doesn't get compared in the whereIn (today it should return 47, 51, 107 and 126 but it only returns 47 and 51), even if they are in the first collection.

I have been able to fix it by using an array:

$first = Users::select('id')->where('column', condition1)->where('column2', condition2)->get();
$test = [];
$n = count($first);
for ($i=0; $i < $n; $i++) { 
    $test[$i] = $first[$i]->id;
}

And it works, but I still don't understand why now I need that extra step without any change in any variable in the function.

Thanks in advance.

08 May
1 year ago

Corban left a reply on Do You Know Why This Error "Trying To Get Property Of Non-object" Is Appearing?

In the dump you are getting property of non-object because you are trying to get a variable of a collection, instead of ->get() using, for example, ->first() should return the first relationship ok. Trying to dump a variable of a collection will always end like this, just return the whole $pastRegistration.

In the blade file that error appears because your relationship is null, so you are trying to access a variable that doesn't actually exist in that record, a workaround could be wraping it in an optional:

@foreach($pastRegistrations as $pastRegistration)
    <h5>{{ optional($pastRegistration->congress)->name}}</h5>
@endforeach
11 Apr
1 year ago

Corban left a reply on Creating A Table With Blade

I don't understand the design. I mean, ok, right now you have only two drivers, but once you get like 100 the table would look really hard to read. Wouldn't be easier with the second option?

Your actual table

Statistics | 1 | 2 ---- | ---- | ---- Driver Name | Jhon | Mary Origin | Downtown | Uptown

This, with 100 records would look too wide. Instead looking to this design wouldn't be enough?

Statistics | Driver Name | Origin ----| ---- | ---- 1 | Jhon | Downtown 2 | Mary | Uptown

With the second option you would only need one foreach, in order to accomplish the first one you should go with two different foreachusing the same collection.

09 Apr
1 year ago

Corban left a reply on Sending Mail Issue

Like @Snapey said there's a difference between gmail/mailgun and mailtrap. Redundant as it is mailtrap is a trap that doesn't let the mail reach it's recipient, instead they store it in your mailtrap account so log in and check your mailtrap inbox.

BTW, if that is your actual code you are not returning a view, you are still with the view.name that artisan includes as example, put a real view there.

21 Mar
1 year ago

Corban left a reply on Make Computed Fields Data-tables In Vuejs/vuetify Librray

First one, you could use a mutator and return the formated date (this goes in your model):

public function getformatedDateAttribute(){
return $this->date->format('%d/%B/%Y);
}

Then in your view just call it instead of the colunm name:

@{{ data.formated_date }}

Second one I'm not sure, but what about using a v-btn with an icon?

Last one I don't understand what you actually want, so sorry.

Hope it helps.

18 Feb
1 year ago

Corban left a reply on Maatwebsite/Laravel-Excel How To Manipulate A Row If The Result Is Equal To A Specific Value

@pickab00 no problem, I have updated my initial answer changing the row with the cell. I used "C" since for what you have showed that's the column you want to edit, if not just change it.

Hope it helps.

Corban left a reply on Maatwebsite/Laravel-Excel How To Manipulate A Row If The Result Is Equal To A Specific Value

@pickab00 mmmm, ok. Try the xlsone when you can, I'll research a bit more when I have time.

The function seems to be right, I have tried it and works perfectly (the green is actually a bit dark btw, and makes the row hard to read, my fault).

Corban left a reply on Maatwebsite/Laravel-Excel How To Manipulate A Row If The Result Is Equal To A Specific Value

@pickab00 Maybe is taking too long to generate? Check set_time_limit() to see if there's the problem.

Corban left a reply on Maatwebsite/Laravel-Excel How To Manipulate A Row If The Result Is Equal To A Specific Value

It's very likely that there would be a better and cleaner way, but I'm assuming you are using a foreach to navigate through all the rows, so why not just add a condition?

Excel::create('Report', function($excel) use($clean){
      $excel->sheet('Sheet 1', function($sheet) use($clean){
        $sheet->row(1, array('Room Attendant Name', 'Room Number', 'Verified'));

        $i = 2;

        foreach ($clean as $example) {

    if($example->col3 == 1){
        $sheet->row($i, function($color){
            $color->setBackground('#008000')
        }
    }

          $sheet->row($i, array($example->relation->name .' '.$example->relation->lastname, $example->col2, $example->col3));
          $i++;
        }

        $sheet->setAutoFilter();
      });
    })->download('xlsx');

I think something like that should work, but can't assure it at 100% since I don't usually manipulate the style of rows. If you find a better way please let me know since I think in the future I'd probably need it as well.

18 Jan
1 year ago

Corban left a reply on Download Series

There's a big download button below each lesson title. I have downloaded a few to watch them while travelling.

16 Jan
1 year ago

Corban left a reply on Help Figuring Out The Proper Relationship

You should make something more logical to explain, like there's a storyteller that can send invites to ohter storytellers and things like that, that should help both you and us to come with an idea.

If I understand correctly, exercises are both storytellers and invites? I can't understand 100% what you are actually trying to relate.

01 Jan
1 year ago

Corban left a reply on Trying To Get Property Of Non-object

For me, this usually appears either when I'm trying to format a null value or when I'm calling a relationship in null.

I don't know if it's the best solution, but the problem is either in one of these three: {{ $nezavrsena->kupac->imeprezime }}, {{ $nezavrsena->user->name }} or {{ $nezavrsena->created_at->format('d.m.Y') }}. Just wrap them them with an optional() and you are done.

Keep in mind that the last part must be outside of the brackets, ex: {{ optional($nezavrsena->user)->name }} or in the case of format {{ optional($nezavrsena->created_at)->format('d.m.Y') }}.

Hope it helps.

29 Dec
1 year ago

Corban left a reply on How To EDIT Posts / Items / Threads

Editing a post/task/anything is just like creating a new one but with a patch request and a update method instead of post and create.

Edit.blade.php:

<form action="/editpost/{{$post->id}}" method="post">
    {{  csrf_field() }}
    //method field is used to tell the browser that this "post" is actually a patch request
    {{ method_field('PATCH') }}
    // Here goes the edit form that can be exactly like your create post but with the values of the post you are editing
    //be sure to pass the id of the post with a hidden input
</form>

web.php:

Route::patch('/editpost/{id}', '[email protected]');

PostController:

public function update($id){

    //validate as usual
    request([
         'field1' => 'required',
         'field2' => 'required'
        ]);

    //Now instead of just creating a new one we are going to update the one we want
    Post::find($id)->update([
        'title' => request('title'),
            'channel_id' => 2,
            'description' => request('description')
    ]);

    //some fancy feedback message       

    return back()
}

And yep, that's all you need. If you are able to create post you shouldn't have more problem editing them. Just remember that you need to find the post you want to update using the id, that you need to submit a patch request (or make it with a post if you want but using get+post+patch+delete let's you make everything with one single route.

The Trying to get property of non-object means that you are passing a null value either through a relationship or to a value you are using in some logic (for example a null date that you are formatting).

26 Nov
1 year ago

Corban left a reply on Laravel Route Parameters

Choosing Route::get('/category/{category}', '[email protected]'); and the equivalent for product is not an option?

Corban left a reply on Associating With Users Part 2: Field 'user_id' Doesn't Have A Default Value

What you don't understand is the protected $fillable ?

Basically you have two options and there's always one needed in order to insert data to your BBDD.

$fillableis a whitelist, that means that if you have that in your model only the values whitelisted can be added to your BBDD. Since you didn't have user_id whitelisted you couldn't add it's value to the database, and because you didn't let it be null you were getting the error.

$guardedis the other option. This is the opposite, a blacklist, so if you use protected $guarded = ['user_id']you won't be able to insert data into that field. This cant be used as a shortcut in big tables where you want to write in every field. Just use protected $guarded = []and you won't have issues of fields that you can't write or remember to add a new field if you edit the table of that model. That said be aware that this can be a problem depending on what your app is for and especially what info your table stores.

25 Nov
1 year ago

Corban left a reply on Associating With Users Part 2: Field 'user_id' Doesn't Have A Default Value

We would need to see a bit more of your code but I have a few ideas of what could be but at least I can suggest that you are not logged, so auth is passing a null value and since user_id can't be null they expect you to have a default value in the BBDD.

21 Nov
1 year ago

Corban left a reply on Relationship Help

So if I understand correctly: You have a clinic, let's call it Clinic 1.

  • Clinic 1 cover a lot of residential areas which are defined by their ZIP code.
  • Each ZIP code belongs to only one clinic, so if 55222 code is attached to Clinic 1 it can't be attached to any other clinic.
  • Each ZIP code is part of the ZIP codes of a location.
  • That means that ZIP code 55222 is part of LaracastLand, which divides it's are in ZIP codes.

With that in mind I believe you want to know how to retrieve which clinics belong to LaracastLand and in which location is clinic 1 located, right?

Then I think the approach should be like this:

  • A clinic hasManyZIP codes.
  • A ZIP code belongsTo a clinic, but a ZIP code also belongsTo a Location.
  • A location hasManyZIP codes, *but *, because this relationship, also has many clinics, which are related using a hasManyThroughrelationship.

Using that relationship you can retrieve the locations of a clinic using ZIP codes. Let me know if that suits your needs. Check hasManyThrough relations from the documentation

07 Nov
1 year ago

Corban left a reply on Set Logout Route In Laravel 5.5

Can we see your code?

There's no real need of POST, you can also use get and just call /logout

Anyway something like this should work if you are using laravel 5.5

YourViewName.blade.php

//some code here...

<form class="" action="index.html" method="post">
  {{ csrf_field() }}
  <button type="submit" name="logout">Logout</button>
</form>

//maybe more code here

your web file

//other routes here
Route::post('/logout', '[email protected]');

your sessionscontroller

public function Logout(){
    auth()->logout();

    session()->flash('message', 'Some goodbye message');

    return redirect('/login');
  }

Corban left a reply on How To Test Emails?

(https://laracasts.com/series/laravel-from-scratch-2017/episodes/26) literally how to create and test Mails in 5.4.

29 Oct
1 year ago

Corban left a reply on How To Fix Undefined Variable: Task (View: C:\Users\Lilan\Desktop\ddd\resources\views\files\form.blade.php) In Laravel

@Flex I was looking at tasks/show.blade.php.

Either way I think your foreach has an error. I remember having a similar issue.

Try it this way in form.blade.php

@foreach ($task->project as $projects)
        <div>
             <div><i class="fa fa-check-square-o"></i>
                <span>
            <a href="{{ $project->files->file_url }}" target="_blank">{{ $project->files->file_name }}</a>
</span>
                    </div>
                </div>
                <hr/>
 @endforeach 

Corban left a reply on How To Fix Undefined Variable: Task (View: C:\Users\Lilan\Desktop\ddd\resources\views\files\form.blade.php) In Laravel

If a project has many task then you are passing a collection. Have you tried using a foreach?

24 Oct
1 year ago

Corban left a reply on Passing Values Form Related Tables To Blade

@Snapey Oh didn't knew about that. Thanks, I'm going to check it.

Corban left a reply on Passing Values Form Related Tables To Blade

@Boubou Try this way:

namespace App\Http\Controllers;

use App\User;

class AdminController extends Controller
{


public function Index() {

    $users = User::all();

    return view('admin.users-view', compact('users'));
  }

}

Corban left a reply on Passing Values Form Related Tables To Blade

Yeah sorry, I just got home and I'm a bit tired. I updated the post (check the code again please), it's role for users and user for role, the rest of the explanation is the same.

Basically you need to have both ends of the relationship in the opposing models.

If you have both it should work.

Sorry for the mistake.

Corban left a reply on Passing Values Form Related Tables To Blade

Did you set the other end of the relatiosnhip?

I'm 99'999% sure that you are doing it in the wrong direction (but maybe you are doing something different to what I'm thinking).. A role can have many users

Role.php

public function role(){
    return $this->hasMany(Role::class);
}

But an user can only have one role, that's why you have it's id in your users table. User.php

public function user(){
    return $this->belongsTo(User::class);
}

Were are you using the hasRole one? You can put it in the blade file directly.

22 Oct
1 year ago

Corban left a reply on How To Get Length More Than 191

How long do you need it to be? Maybe you should go with one of the [text]{https://laravel.com/docs/5.5/migrations#creating-columns} variants

Corban left a reply on Create Doesn’t Work Even With Empty Guarded Array

Can you post the code of your form and your store function?

21 Oct
1 year ago

Corban left a reply on I Cant Access Artisan Migrate On Windows

What do you mean you can't access.

Post some error code or at least the steps you are following so we can figure out something.

20 Oct
1 year ago

Corban left a reply on Delete From Database.

@imposition oh don't mistake me. I don't care if I get that mark or not as long as it helps people.

Just asked because at first you said it didn't work so I wanted to know were I failed to not make the same error again.

19 Oct
1 year ago

Corban left a reply on Delete From Database.

@imposition I'm having a really hard time finding what did you change to make it work, it looks exactly like my answer (it's not a blame, I'm glad it helped you).

Were you trying to ctrl+c, ctrl+v exactly what I typed? Then it was obviously going to fail since I didn't knew your variable names.

Anyway, I'm happy it worked

Corban left a reply on Delete From Database.

Where did you paste it? That's going to fail if you don't paste it after importing App\Form (if it even exist a Form class and doesn't have other name).

I'll suggest that you should first try the long way:

<td><a href="/radius/destroy/{{ $your_PK_here }}" class="fa fa-trash" aria-hidden="true"></i></a></td>

Here you shoul call a simple file with a form, so you get a route there

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

Then you just pop up the delete page (FE deletefiles.blade.php) with a form (of course there are a lot of ways to display it in the same page, I'm doing this the long way so you can work from this point and because I'm a bit in a hurry).

<form method="post" action="/destroyradius" class="">
        {{ csrf_field() }}
    {{ method_field('delete') }}
         <div class=""> //jokes on me I tried to use a snippet
        Are you sure you want to delete {{ $yourvariable->name }} ?
     </div>
    <div class="">
        <input type="hidden" value="{{ $yourvariable->columnForWhereDelete }}" name="delete">  
        <button class="" type="submit" >Confirm</button>
        <button class="" type="submit"onclick="window.history.go(-1)" >No, Wait!</button>
    </div>
        </form>

And then you call your destroy method

route::delete('/destroyradius', '[email protected]');
public function Destroy(){
    $toDelete = request('delete');

    Radius::where('name?', reques )->delete();

    return redirect('/');
}

Tell me if it works. If it does but you don't understand something ask and I'll explain each part later.

18 Oct
1 year ago

Corban left a reply on Property [products] Does Not Exist On This Collection Instance.

@tomwebb Can you explain further? Maybe show us your Controller and how you want to display that in your view?

Best thing that comes to my mind in this state and as sleepy as I am is that maybe you could try changing orderByDesc for sortByDesc since you already have an array.

PS: for bnazarov suggestion just:

public function scopeBestCategories($query)
{
  $rightNow = $query->get();

  $best = $rightNow->products->orderByDesc(function($item) {
      return $item->reviews->amazin_score;
  });

dd($best)

  return self::whereIn($best->pluck('node_id'));
}

This should show in the browser an array of what you are returning.

Corban left a reply on Why Laravel Add An Extra Where Condition "foreign Key Is Not Null" To HasOne/Many Relation?

But your example is using a One to One relationship. The whole thing makes sense to me since every time I have used a One to One relationship is because those tables need to be always related, so null is not a valid option.

Of course this is probably debatable since I don't have the same amount of experience that a lot of users here, but I think that the key problem is that you mistook hasOne and hasMany and (as me and I believe almost everyone here) wanted to satisfy your curiosity.

17 Oct
1 year ago

Corban left a reply on Menu Controller Is Not Found Laravel 5.5.check My Code Please And Help Me Where Am Wrong

@usmanali0458 mark the question as answered to help others with the same problem.

About the format, it was ok until the last part you forgot to highlight the submenu code. Don't worry since we found the solution (which is great :D ).

I still think that loading submenu is not necessary, but I don't know how is the rest of your code structured so don't mind me.

Corban left a reply on Menu Controller Is Not Found Laravel 5.5.check My Code Please And Help Me Where Am Wrong

Try to update the question with the correct format, at first I was going to ask if you didn't have the belongsTo relationship.

I think you are overcomplicating things.

Just:

public function menu()
{

        $menu = Menu::all();

    return view('menu', compact('menu'));
}

And in your menu.blade.php:

@foreach ($menu->submenu as $dates)
    {{ $dates->date }}
@endforeach

Corban left a reply on SortBy And Accented Words

Oh ok, now I get it. I was sorting after fetching with ->get() since I was using the ::all()method, I'm still getting used to Eloquent.

Thanks @andonovn and @florianhusquinet for the explanation.

16 Oct
1 year ago

Corban left a reply on SortBy And Accented Words

I tried the orderByRaw this afternoon before searching and lastly asking. It returns Method orderByRaw does not exist., also tried sortByRaw and the same...

I'll stick with your previous answer until finishing some things tomorrow and I'll begin searching a simpler method in my spare time.

Corban left a reply on SortBy And Accented Words

@florianhusquinet yeah it worked! Well, actually I had to make a minor change since it looked like 'fr_FR' didn't work, but changing it to 'French' seemed to do the trick.

I'll take your advice and try to change the query (is just a simple Select id, name, last_name FROM employees OrderBy but since there's no sortByRaw method I suppose you mean a whole raw query without eloquent? I'll check that.

@andonovn thanks, it didn't work but now I know that DB collations can't be passed in the query, they go in the config/database file.

Corban left a reply on How To Display Users Products?

Inventory is the name of the pivot table? Then something like this;

class Product extends Model
{
    protected $table = "products";
    public $fillable = ['name','details','price'];

public function users(){

    return $this->belongsToMany(User::class, 'Inventory');
  }

}

class User extends Model
{
    public function products(){

    return $this->belongsToMany(Product::class, 'Inventory');
  }
}

then to return the value in an hypothetical User View something like:

@foreach ($user->products as $product)
  {{$product->name}}
@endforeach 

Corban started a new conversation SortBy And Accented Words

Hello everyone, I have a problem that I suppose has a really easy and obvious answer that I can't figure right now.

Right now I'm using the simplest of simplest queries to populate a select list. My problem is that when I use ->sortBy('last_name') the majority of names appear in the right order, but two of them that start with "Á" appear at the end of the list. It's there something that I should add? There is no need of the 'Desc' part since the rest of "A" last names appear at the start.

Thanks for your time.

12 Oct
1 year ago

Corban left a reply on Tweaking The Layout

@JeffreyWay Cool, thanks.

11 Oct
1 year ago

Corban left a reply on Tweaking The Layout

Just posting to check if the double post issue was resolved.

10 Oct
1 year ago

Corban left a reply on Failed To Display Data With `whereNotNull` Method

You forgot to fetch the results. Add ->get() at the end of your query.

public function index()
{
    $channels = Channel::whereNotNull('user_id')->get();

    return view('channels.master', compact('channels'));
}

Corban left a reply on Failed To Display Data With `whereNotNull` Method

You forgot to fetch the results. Add '->get()' at the end of your query.

''' $channels = Channel::whereNotNull('user_id')->get(); '''

24 Sep
1 year ago

Corban left a reply on Laravel Web App And Local App

I doubt there's some kind of magic trick that allows an offline app to upload content. I'll go with @jlrdw and suggest to create a local app where you export the data at certain intervals. If you use Access/VBA there are some ways to protect with password your VBA code and to lock use of the nav pane and menus.

Another option is to create your main app and then replicate it in a local VM.

The offline areas have their own network or are isolated PCs?

20 Sep
1 year ago

Corban left a reply on Auto Registration By Php Laravel

You are talking about a new project, did you already migrate the tables? Are you using the default ones for users? If not just put "protected $table = 'YourTableName';" in the model. Maybe you forgot something in the .env file?

Corban left a reply on Auto Registration By Php Laravel

You are talking about a new project, did you already migrate the tables? Are you using the default ones for users? If not just put "protected $table = 'YourTableName';" in the model. Maybe you forgot something in the .env file?

Corban left a reply on Auto Registration By Php Laravel

You are talking about a new project, did you already migrate the tables? Are you using the default ones for users? If not just put "protected $table = 'YourTableName';" in the model. Maybe you forgot something in the .env file?