Member Since 4 Years Ago

Experience Points 2,230
Experience Level 1

2,770 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 33
Best Reply Awards 0
Best Reply
  • 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.


    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.


    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.

04 May
3 months ago

lonerunner left a reply on Auth::user() Returns Null With Using Global Middleware

@SNAPEY - You are correct, i wasn't aware of that, so when i moved my LastSeen middleware to the bottom of the list, it started working now. Thank you very much.

03 May
3 months ago

lonerunner started a new conversation Auth::user() Returns Null With Using Global Middleware

I am trying to create last user activity, and i've been reading some instructions on middlewares but i am confused, i previously built middleware for role check and that successfully works when i put middleware in $routeMiddleware because that should be routed middleware, now i am reading on and there is global middleware which says:

If you want a middleware to run during every HTTP request to your application, list the middleware class in the $middleware property of your app/Http/Kernel.php class.

So this means middleware would run every possible time, which i need.

So i created middleware LastActivity in \App\Http\Middleware\LastActivity.php

I registered middleware in global middleware in Kernel.php

    protected $middleware = [

And if i try to simply do this in middleware:

$user = Auth::user();


I get null or false, as user is not loged in.

But if i move middleware to web group

   protected $middlewareGroups = [
        'web' => [

Than it works, so why it doesn't catch in global? Am i missing something here, i still didn't tested with api requests but i'm afraid it won't work per explanation i read on middleware page. But i will need it for api requests too, so global middleware would be solution.

25 Apr
3 months ago

lonerunner left a reply on Vue Js V-for Not Working When Array Passed Through Props

@FLORIANSCHOMMERTZ - Thanks for clarification, that's exactly what i wanted to find out, difference between using quotations and not using them. I am new to vue js and i just started learning, about underscore so this means best practice would be to use camel case in any prop names.

lonerunner left a reply on Vue Js V-for Not Working When Array Passed Through Props

I got an answer, i don't know why it's making differences as im still learning on vue, but comma's in blade made it work.

So instead this:

:input_value="'{{ json_encode($profilephotos) }}'"

I should write it like this

:input_value="{{ json_encode($profilephotos) }}"

lonerunner started a new conversation Vue Js V-for Not Working When Array Passed Through Props

I don't get it for some reason when i pass array through props v-for wont work and only difference i can see from directly writing data is that one passed from props don't have spaces in between.

I am using laravel and through blade im passing data to vue, data is array of all photos with informations. But that data won't list through all photos and display div's.

Let me show you my code:

This is what i have in blade template:

    :input_value="'{{ json_encode($profilephotos) }}'"
    :bind_user="'{{ $profile->id }}'"
    :post_url="'{{ route('photouploads') }}'"

I don't think that json_encode make difference in this case but i tried it any way.

And this is what i have in my photos.vue file

props: ['input_name', 'post_url', 'bind_user', 'type', 'input_value'],
    data() {
        return {
            files: [],
            uploads: this.input_value,
            items: [
              {"id":110,"user_id":28,"type":"profilephoto","name":"5.jpg","mime":"image/jpeg","extension":"jpg","path":"3f49191095d302fb7e66ce037dd5efa111287e8230964ad8a3170687ca4336a1","size":192445,"created_at":"2019-04-23 16:04:01","updated_at":"2019-04-23 16:04:01"},
              {"id":111,"user_id":28,"type":"profilephoto","name":"4.jpg","mime":"image/jpeg","extension":"jpg","path":"0bd693c2cd1ab5ec2c7223fc6a92356ab68c52e8cc0b7d5d5aa5b4a230cf015b","size":193223,"created_at":"2019-04-23 21:58:52","updated_at":"2019-04-23 21:58:52"},
              {"id":112,"user_id":28,"type":"profilephoto","name":"5.jpg","mime":"image/jpeg","extension":"jpg","path":"0bd693c2cd1ab5ec2c7223fc6a92356ab68c52e8cc0b7d5d5aa5b4a230cf015b","size":192445,"created_at":"2019-04-23 21:58:52","updated_at":"2019-04-23 21:58:52"},
              {"id":113,"user_id":28,"type":"profilephoto","name":"4.jpg","mime":"image/jpeg","extension":"jpg","path":"ffe6f95d10c5249390fcea140fe15a1fb57f5d29626a947e4a999db50f3ea295","size":193223,"created_at":"2019-04-23 22:00:10","updated_at":"2019-04-23 22:00:10"},
              {"id":114,"user_id":28,"type":"profilephoto","name":"4.jpg","mime":"image/jpeg","extension":"jpg","path":"75a00a901f1a01a0267d44bebc8574efa9eb7a7edfd395e29dabb289efb353ac","size":193223,"created_at":"2019-04-23 22:05:32","updated_at":"2019-04-23 22:05:32"}

So input_value is what is passed from blade template, and items is what i added manually for testing, items is exactly the same as what i see when i output data in frontend.

Here is what i have in .vue <template> section

{{ items }}

<li v-for="item in items">
   {{ item.type }}

{{ uploads }}

<div v-for="upload in uploads">
  {{ upload.type }}

So items should output complete array and v-for should filter and output foreach item in that array, which should go the same for uploads but problem is uploads not working.

This is what i actually get in frontent

For {{ items }}

[ { "id": 110, "user_id": 28, "type": "profilephoto", "name": "5.jpg", "mime": "image/jpeg", "extension": "jpg", "path": "3f49191095d302fb7e66ce037dd5efa111287e8230964ad8a3170687ca4336a1", "size": 192445, "created_at": "2019-04-23 16:04:01", "updated_at": "2019-04-23 16:04:01" }, { "id": 111, "user_id": 28, "type": "profilephoto", "name": "4.jpg", "mime": "image/jpeg", "extension": "jpg", "path": "0bd693c2cd1ab5ec2c7223fc6a92356ab68c52e8cc0b7d5d5aa5b4a230cf015b", "size": 193223, "created_at": "2019-04-23 21:58:52", "updated_at": "2019-04-23 21:58:52" }, { "id": 112, "user_id": 28, "type": "profilephoto", "name": "5.jpg", "mime": "image/jpeg", "extension": "jpg", "path": "0bd693c2cd1ab5ec2c7223fc6a92356ab68c52e8cc0b7d5d5aa5b4a230cf015b", "size": 192445, "created_at": "2019-04-23 21:58:52", "updated_at": "2019-04-23 21:58:52" }, { "id": 113, "user_id": 28, "type": "profilephoto", "name": "4.jpg", "mime": "image/jpeg", "extension": "jpg", "path": "ffe6f95d10c5249390fcea140fe15a1fb57f5d29626a947e4a999db50f3ea295", "size": 193223, "created_at": "2019-04-23 22:00:10", "updated_at": "2019-04-23 22:00:10" }, { "id": 114, "user_id": 28, "type": "profilephoto", "name": "4.jpg", "mime": "image/jpeg", "extension": "jpg", "path": "75a00a901f1a01a0267d44bebc8574efa9eb7a7edfd395e29dabb289efb353ac", "size": 193223, "created_at": "2019-04-23 22:05:32", "updated_at": "2019-04-23 22:05:32" } ]

And there v-for="item in items" logic works, if i do

<li v-for="item in items">
   {{ item.type }}

I will get list of item.type

The problem happens if i do exactly the same with uploads something is not working.

If i test output of {{ uploads }} i will get exactly same array as with items except there are spaces between things in array.

This is output of {{ uploads }}

[{"id":110,"user_id":28,"type":"profilephoto","name":"5.jpg","mime":"image/jpeg","extension":"jpg","path":"3f49191095d302fb7e66ce037dd5efa111287e8230964ad8a3170687ca4336a1","size":192445,"created_at":"2019-04-23 16:04:01","updated_at":"2019-04-23 16:04:01"},{"id":111,"user_id":28,"type":"profilephoto","name":"4.jpg","mime":"image/jpeg","extension":"jpg","path":"0bd693c2cd1ab5ec2c7223fc6a92356ab68c52e8cc0b7d5d5aa5b4a230cf015b","size":193223,"created_at":"2019-04-23 21:58:52","updated_at":"2019-04-23 21:58:52"},{"id":112,"user_id":28,"type":"profilephoto","name":"5.jpg","mime":"image/jpeg","extension":"jpg","path":"0bd693c2cd1ab5ec2c7223fc6a92356ab68c52e8cc0b7d5d5aa5b4a230cf015b","size":192445,"created_at":"2019-04-23 21:58:52","updated_at":"2019-04-23 21:58:52"},{"id":113,"user_id":28,"type":"profilephoto","name":"4.jpg","mime":"image/jpeg","extension":"jpg","path":"ffe6f95d10c5249390fcea140fe15a1fb57f5d29626a947e4a999db50f3ea295","size":193223,"created_at":"2019-04-23 22:00:10","updated_at":"2019-04-23 22:00:10"},{"id":114,"user_id":28,"type":"profilephoto","name":"4.jpg","mime":"image/jpeg","extension":"jpg","path":"75a00a901f1a01a0267d44bebc8574efa9eb7a7edfd395e29dabb289efb353ac","size":193223,"created_at":"2019-04-23 22:05:32","updated_at":"2019-04-23 22:05:32"},{"id":115,"user_id":28,"type":"profilephoto","name":"4.jpg","mime":"image/jpeg","extension":"jpg","path":"c0db13b85c255a30b8466ca5778cad05d06f20f2cf12a3db46e9b6a7d182fdd8","size":193223,"created_at":"2019-04-23 22:14:37","updated_at":"2019-04-23 22:14:37"},{"id":116,"user_id":28,"type":"profilephoto","name":"4.jpg","mime":"image/jpeg","extension":"jpg","path":"3591cedc64c8f3638d71643291ce2e37d697dbcdfe08c715254d94237b93b1a1","size":193223,"created_at":"2019-04-23 22:21:37","updated_at":"2019-04-23 22:21:37"}]

And if i try to do

<div v-for="upload in uploads">
  {{ upload.type }}

I get whole bunch of empty div's without upload.type output. Plus i have like 20 images in total, i get like 200 empty div's.

This confuses me alot as why it is happening like this, any suggestions?

23 Apr
3 months ago

lonerunner started a new conversation Best Way To Have Reusable Array Across Controllers And Views

What would be your suggestion for best way to utilize use of variable with array info across multiple controllers and views.

For example i have a list of countries and list of categories, something like

$countries = array(
    'us' = 'United States',
    'de' = 'Germany',
    'nl' = 'Netherland',

$type = array(
    'sm' = 'Small',
    'md' = 'Medium',
    'lg'    = 'Large',
    'xl'  = 'Extra large'

To avoid getting another query call I usually would write variable like this in global scope and use it in multiple templates when needed, but that's what i do with wordpress sites.

What would be suggested solution for Laravel framework?

I need to use this in multiple views and controllers, instead of writing every time in each controller, and creating select list in each blade file, i could use array from variable to generate list of options.

15 Apr
4 months ago

lonerunner left a reply on How To Update/sync Table Data For Each Row From Input Field Array ?

@SNAPEY - That's what i did in the end, in my User model i sorted out retrieving of messages by id

    public function messages() {
      return $this->hasMany(Message::class)->orderBy('id');

But i still fail to see this as correct behavior, i might no be expert in laravel, this is my second learning project, but i work on development for over 5 years with different cms and custom php projects and it never ever happened to me that row with id lower than previous one get's recorded in database after. So i never saw 81 to go after82.

I have another table on same project and it also have maas input from checkbox fields but on that one everything goes in correct order of insert, and i don't have to use orderBy

But ok, i got to understanding that not every time records would be saved in database in order of input, so i have to use orderBy filter.

14 Apr
4 months ago

lonerunner left a reply on How To Update/sync Table Data For Each Row From Input Field Array ?

@SNAPEY - I don't, i replied before on your post, but i think you don't see real picture why i think there is a problem, take a look at my last post, specially at screenshot,


Database never ever save data with incremental id's out of order, and also with that, it saves my array data out of order, fourth one is saved as first one. This shouldn't happen, last message in array should be saved as last row in database table.

In last post as you can see i figured what is making it do it like that, i just don't know if it's a bug in laravel, or php, or database, or i just use wrong function for my purpose.

lonerunner left a reply on How To Update/sync Table Data For Each Row From Input Field Array ?

Alright i finally figured out what is making problem with writing data out of order in database. delete() is what make it out of order.

So when i am updating messages, i need to delete old ones first before writing new records in database, if you take a look at my previous posts i used delete() to delete all messages by that user id before adding new ones in database.


deleted messages first, than:

if(is_array($request->messages)) {
  foreach($request->messages as $message) {
         $user->messages()->create(['user_id' => $user->id, 'message' => $message]);

Adding new ones.

I just tested to submit new data, and this time i commented out $user->messages()->delete(); tried multiple times, and every time messages array have been saved in proper order on database.


Well i guess now i need to figure out how to find solution to this problem.

lonerunner left a reply on How To Update/sync Table Data For Each Row From Input Field Array ?

@BOBBYBOUWMANN - Nothing strange that would make order out of order. As you can see in my second answer is all what i do.

In my blade.php file input fields are in proper order 1,2,3,4,5... when i submit form, data get's ordered in same array order as i posted before, and all i do in my controller is what i also posted earlier, very similar to your example, i list array and save each one of them.

As i noted all inputs are saved with exactly same timestamps in database so on my latest try i added 5 seconds sleep sleep(5) for each loop and now fields were recorded in order but reverse, strange, i dropped messages table and recreated again, but it's the same.


I checked all other tables, like users table and ofcourse as it should increment is going in proper order 1,2,3,4... not reverse like this one.

lonerunner left a reply on How To Update/sync Table Data For Each Row From Input Field Array ?

@BOBBYBOUWMANN - I know that, problem i have is, id keys in database are saved out of order somehow, instead of having id's 23, 24, 25, 26. In database i have like 26, 25, 23, 24.

Take a look at screenshot.


lonerunner left a reply on How To Update/sync Table Data For Each Row From Input Field Array ?

Array from frontend seems fine, this would be generated form on front end

<input type="text" name="messages[0]" id="messages" class="form-control" >
<input type="text" name="messages[1]" id="messages" class="form-control" >
<input type="text" name="messages[2]" id="messages" class="form-control" >
<input type="text" name="messages[3]" id="messages" class="form-control" >
<input type="text" name="messages[4]" id="messages" class="form-control" >
<input type="text" name="messages[5]" id="messages" class="form-control" >

So when i submit form and check output on that field $request->messages i get normal array order


array:10 [▼
  0 => "This is first message"
  1 => "And now second one"
  2 => "Third over here"
  3 => null
  4 => "This should be fourth one"
  5 => null
  6 => null
  7 => null
  8 => null
  9 => null

I tried 2 different approaches now, one is:

if(is_array($request->messages)) {
   foreach($request->messages as $message) {
       $user->messages()->save(new Message(['message' => $message]));

This does same thing as create() and another approach i tried is createMany()


But this save empty array fields too.


Shouldn't ordered id's in database be like: ?

| id | user_id |         message          |
|  4 |      12 | First message            |
|  5 |      12 | And now second message   |
|  6 |      12 | This is third message    |
|  7 |      12 | This should be forth one |
13 Apr
4 months ago

lonerunner started a new conversation How To Update/sync Table Data For Each Row From Input Field Array ?

So i have multiple input field into array

<input type="text" name="messages[{{ $i }}]" id="messages" class="form-control" >

Each $i represents loop array, and from that array i need to save each one on separate row, at the same time that need to be kinda synced so deleting old data for that user and inserting new one.

Currently i have this, and this actually works, problem is, it saves row's in database in kinda odd way that they don't go arranged in order.

So in my User model i have this

public function messages() {
      return $this->hasMany(Message::class);

When i hit update button on my page, in my UserController i have this:

$user = User::find($id);

$user->name = $request->name;
$user->lastname = $request->lastname;



if(is_array($request->messages)) {
  foreach($request->messages as $message) {
         $user->messages()->create(['user_id' => $user->id, 'message' => $message]);

So this works, but order of messages in table is out of order:

| id | user_id |         message          |
|  6 |      12 | This is third message    |
|  5 |      12 | And now second message   |
|  4 |      12 | First message            |
|  7 |      12 | This should be forth one |
02 Apr
4 months ago

lonerunner left a reply on ManyToMany Relationships And Attach Without Pivot Table From Input Field Array

I still don't get it im either doing something wrong or don't understand relationships quite correctly. I think maybe im missing a point with belongs to, has many, has one.

Thing is that both operators and profiles are actually using same database which is users from db table and they have id from that table so it might be mistake in relations, but operator can manage many users and user can have only one operator.

I read more on documentation and tried @bobbybouwmann examples and few variations but none works, so far i found only this as solution

      $user = new User;

      $user->name = $request->name;
      $user->email = $request->email;
      $user->password = bcrypt($request->password);


      $user->roles()->attach(Role::where('name', 'operator')->first());

      $user->profile()->create(['user_id' => $user->id, 'gender' => $request->gender]);

      foreach($request->profiles as $profile) {

      $operator = new Operator;

      $operator->operator_id = $user->id;
      $operator->profile_id = $profile;


But im sure, im breaking my brain overhere, this is not the laravel way solution. Plus i didn't test this when i already have operator and want to update profiles he manage, i would have to sync database and find all id's with operator id, remove records where profile id don't exist in new array and add new record if new profile id is in array.

For roles with pivot table that works with sync()

01 Apr
4 months ago

lonerunner started a new conversation ManyToMany Relationships And Attach Without Pivot Table From Input Field Array

I have Users and Operators, and each User can have only one operator, but Operator can have many users

So in Operator model i have:

  public function profile() {
    return $this->hasMany(User::class);

And in User model i have:

    public function operator() {
      return $this->hasOne(Operator::class);

So i think i got relationships right ?

Now if i have input field to manage operators and on that i have multiselect box so i can select many users to add to that operator, input field would be something like:

<select name="profiles[]" id="profiles" multiple="multiple" class="multiselect2 form-control">
    @foreach($profiles as $key => $profile)
    <option value="{{ $profile->id }}">{{ $profile->name }} {{ $profile->lastname }}</option>

On form submit that would post an array of all selected $profiles (those are users from user table)

What goes a bit tricky for me is when i am creating new operator and select which users to attach to operator, i don't know how could i add them and sync without having pivot table, and i don't need pivot table at all for this.

i have operators table and that one should hold operator id's and managed users id's

| id | operator_id | user_id |
|  1 |           3 |      23 |
|  2 |           3 |      28 |
|  2 |           3 |      36 |

So how can i add (attach or connect) user id's of operators and managed users in operators table?

Here's my current controller code

$user = new User;

      $user->name = $request->name;
      $user->email = $request->email;
      $user->password = bcrypt($request->password);


      $user->operator()->attach(['operator_id' => $user->id,  'profile_id' => $request->profiles]);
30 Mar
4 months ago

lonerunner left a reply on Laravel Retrieve All Users Where Value Match Pivot Table

I think i got relationships right.

One User can have many roles and one profile so User model:

public function roles() {
      return $this->belongsToMany(Role::class);

    public function profile() {
      return $this->hasOne(Profile::class);

Role can have many users but roles belongs to users so Role model:

    public function users() {
      return $this->belongsToMany(User::class);

And also Profile belongs to user so Profile model

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

And actually @Ricardo solution is what it works, i also tried to add filter for profiles too into the mix and it works. It's documented on laravel website, but on search results i never got anything related to whereHas

lonerunner started a new conversation Laravel Retrieve All Users Where Value Match Pivot Table

So im trying to make relationship between user roles and profiles everything works connected on creation but i don't know how to filter out when i want to list users by specific role or profile.

Here is a table structure that i have now. Each table corresponds to it's model, so table users have model User table roles have model Role and there is a pivot table role_user that connects users with roles.

This would be role table

| id |   name   |  Description  |
|  1 | admin    | Administrator |
|  2 | client   | Client        |
|  3 | operator | Operator      |

This would be pivot table for user role

| id | user_id | role_id |
|  1 |       1 |       3 |
|  2 |       2 |       1 |

And this would be user table normally

| id |  name  |      Email      |
|  1 | Mario  | [email protected] |
|  2 | Luighi | [email protected]   |

So if i would list all account that is very simple, as i would just use

public function index(Request $request)

  $users = User::get();

  return view('users/index', compact('users'));

If i want to filter users by specific name or email i would just filter

$users = User::where('name', 'Mario')->get();

That would retrieve all users where matching name is mario.

Now something more complex is where i stumbled upon and i couldn't quite find answers on internet.

I want to retrieve all users where user role from pivot table matches role from role table.

Example would be

Retrieve All Users WHERE (pivot table) role_user EQUALS name OPERATOR from role table

That would return user Mario, as his user id is 1 and in pivot table that user_id matches role_id 3 which in roles table is role named OPERATOR.

23 Aug
2 years ago

lonerunner left a reply on How To Use @if Inside Javascript Object Literal?

I got it finally working with this line of code

{!! $worker->function ? "<footer>$worker->function</footer>" : "" !!}

Although i understand this have security issue with xss possible attack, it's internal website so it's not much of an issue for me.

lonerunner left a reply on How To Use @if Inside Javascript Object Literal?

It's kinda hard coded, since most of the parts on the website are built with 3d and webgl, i can use separate javascript file but it makes no sense, and creating an ajax call is not possible since the this is preloaded prior to the rest of 3d stuff. So i have to kinda make it this way.

EDIT: I made a progress my putting the code together like this (for the part if field is empty or not)

{{ $worker->function ? "<footer>$worker->function</footer>" : "" }}

So this basically now checks if function is empty or not, but i have different problem now, the <footer> gets rendered into the view also so that is not formatted. i get it now like CEO displayed on the page.

lonerunner started a new conversation How To Use @if Inside Javascript Object Literal?

I hope i wrote it correctly, as i remember when you have an array options in javascript these are called object literals. I have a problem i can't find how to use @if statement in object literal. I have a small site and everything is located inside welcome.blade.php template so i don't have separate javascript file, the function that i use is just at the bottom of the template inside tags. So here is the whole function that i have

            var employees = [
                @foreach ($workers->chunk(20) as $chunk)
                    @foreach ($chunk as $worker)
                            innerHTML:'<div class="container-fluid full-height"><div class="row full-height"><div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 full-height"><div class="person-info"><blockquote><h1>{{ $worker->first_name }} {{ $worker->last_name }}</h1>{{{ $worker->function !== '') ? <footer>{{ $worker->function }}</footer> : '' }}}</blockquote></div></div><div class="col-xs-5 col-sm-5 col-md-5 col-lg-5 col-lg-offset-1 col-md-offset-1 col-sm-offset-1 full-height"><div class="person-photo"><img class="img-responsive" src="thumbs/{{ $worker->image }}" /></div></div></div></div>',
                            src:"thumbs/{{ $worker->thumbnail }}"

As you can see i need to get all the info from $workers inside innerHTML and that should be output as html content, but as some fields will be empty in database so i need to write @if statement if those fields are not empty to display some code

{{{ $worker->function !== '') ? '<footer>{{ $worker->function }}</footer>' :  '' }}}

But i can't get it how to get the if statement inside innerHTML content to work.

16 Sep
3 years ago

lonerunner left a reply on Filemanager From A Button To Set Url In Input Text

Since you mention filemanager i kinda guess that you mean on simogeo filemanager, anyway even if you didn't mean that filemanager it's nice manager to take a look, it can be implemented in editors like ckeditor or can be used as standalone and even have an option for what you are looking for https://github.com/simogeo/Filemanager/wiki/How-to-use-the-filemanager-from-a-simple-textfield-%3F

21 Aug
3 years ago

lonerunner left a reply on Auth::validate Without Password, Or Validating By Custom Field?

If user pass all checks, it's not the problem to login the user. If the user steamid exists in database, the email is confirmed and user is confirmed too i can just Auth::login($user).

            $user = User::where('steamid', '=' , $info->getSteamID())->first();

            if ($user) {
                return redirect()->back();

The problem is to authenticate and validate user in steps in between upon first login over steam. Looks like i will go the steps on query on the user

            $user = User::where('steamid', '=' , $info->getSteamID())->first();
        //If user login first time with steam and his id is not in database redirect to email input page
        if(!$user) {
        // else if user exists in database but didn't insert his email redirect to email input page again
        elseif($user && $user->email == '') {
        // else if email already inserted in database user need to check if account confirmed 
        elseif ($user && $user->confirmed) {
            return redirect()->back();

Didn't tested yet but looks like this is the way i know how to do it.

lonerunner started a new conversation Auth::validate Without Password, Or Validating By Custom Field?

I made my user registration on a website and partially i use laravel 5 built in user registration and login. I just customized it a bit and changed so the user will need to confirm his account first by email and token sent in that email.

To validate if user is confirmed or not by confirmation link i added a new field for users confirmed which is true or false.

So on checking if user is validated i use

        if (Auth::validate(['username' => $request->username, 'password' => $request->password, 'confirmed' => 0])) {

This works so when user is not confirmed and try to login he gets failed message because he did not confirmed his email.

BUT NOW THE PART WITH PROBLEM I want to implement steam login with steam oauth and for that i created new field in database steamid

When the user try to login with steam, the website gets response of user ID from steam. So there are few steps, i have to check if that user exists on my website by comparing response ID with steamid in database and also if that user is confirmed or not. If user is confirmed and exists in database log him in. If the user is not confirmed redirect him to email confirmation. And if user does not exists send him and email with confirmation.

As i said for regular logins with username and password the Auth::validate works, but how do i validate if user would use just steamid instead of username and password combo.

10 Aug
4 years ago

lonerunner left a reply on How To Get Html In Response Session Flash Or Redirect With Messages?

This is maybe a rough solution and maybe not up to laravel standard coding, but it will be easy for manage i think and it does perfectly what i need it to do.

So i decided to send redirect with message and name to the view of the message so the code would look like this

return redirect($this->redirectPath())->with('message', 'messages.activationerror');

And than i can use simplest include in my headeer.blade.php template so instead i display message i put the text into include

@if (session('message'))

The @include will now link to the template name inside a message and include it into main template page. Next i made view/message/activationerror.blade.php and i can code and style it any way i want so i can have different messages for different needs, example:

<div class="container">
    <div class="alert alert-warning alert-dismissable">
      <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
      <h4>Oh snap! You got an error!</h4>
      <p>Change this and that and try again. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum.</p>
        <button type="button" class="btn btn-danger">Take this action</button>
        <button type="button" class="btn btn-default">Or do this</button>

And now since this is my test for user activation code if i enter wrong code i get the message with buttons and formatting. I got the idea from View::make('greeting')->nest('child', 'child.view'); example

lonerunner left a reply on How To Get Html In Response Session Flash Or Redirect With Messages?

This can be one of the solutions but i want this to make as a global messages for everything login, logout, registration, activation, post published, profile saved... etc. And some of messages would have a button (bootstrap styled) some 2 buttons different style and some just a message without formatting.

This is what i have in my header.blade.php which is global template used for everything:

@if (session('success_message'))
<div class="container">
    <div class="alert alert-success alert-dismissable">
      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
      <p>{{{ session('success_message') }}}</p>

@if (session('error_message'))
<div class="container">
    <div class="alert alert-warning alert-dismissable">
      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
      <p>{{{ session('error_message') }}}</p>

If i would for example have primary button Login and secondary Reset Password in same message than i would have to have session() for each button and check if there is a session or not and format each one. If i would have 3 buttons i will need to add another session() check.

There is no way to send html in these kind of messages? Even to include another view into main view. I have searched a bit and found a docs for nested views so instead using redirect()->with() Maybe i could try something with nested views so i can pass another view into main view same as messages?

lonerunner started a new conversation How To Get Html In Response Session Flash Or Redirect With Messages?

The basic example would be to display a message to the user upon registration. After user input his data in registration form it gets redirect to home page and get a message of successful registration. And typical example would be:

redirect($this->redirectPath())->with('success_message', 'Thank you for registering you may now login.');

But i want to go a little further and format this message somehow to display a link and to be in two lines for example

redirect($this->redirectPath())->with('success_message', '<h3>Thank you for registering</h3> <br />You may now login with your account credentials. <br /> [login button]');

Is there a way to use html in these kind of messages or other way to display messages in html format?

15 Feb
4 years ago

lonerunner left a reply on How To Retrieve Serialized Data In Form::model And Populate Array Of Form::select With Multiselect

As i see the video is for laravel 5, and the video explains exactly what i need, but i am on laravel 4 and on few forums is already replied that i can't do what i want on laravel 4 (at least not with Form::model), anyway since laravel 5 is out recenly ill do an upgrade and watch whole series from Jeffery way.

@smadeira you completely understood what i want to do, except in addition to regular select i have multiple select forms with multiselect fields, basically i have multidimensional array. I took a quick look at accessors and mutators, and this might help, although it requires a bit more coding for what i need. Anyway ill do upgrade on laravel 5 and see what i can do, since Jeffery way screencast explains exactly what i need.

lonerunner left a reply on Problems With CRSF In Laravel 5

@bestmomo sorry for bumping an old thread but i don't want to open new one as i have a same error and this might be an answer, just a quick question.

So everything that i had in my routes before like:

Route::group(['before' => 'auth'], function() {

    //CSRF protection
    Route::group(['before' => 'csrf'], function() {
        // Account change password POST form
        Route::post('/account/change-password', [ 'as' => 'account.change.password.post', 'uses' => 'AccountController@postChangePassword' ]);

I can remove csrf from routes and simply use

Route::group(['middleware' => 'auth'], function() {

And it will be the same thing?

13 Feb
4 years ago

lonerunner started a new conversation How To Retrieve Serialized Data In Form::model And Populate Array Of Form::select With Multiselect

I have a serialized data saved in my database, it's a values from array of categories. I created this because it's easy to manage what categories are selected.

So for creating a "page" i created create.blade.php page and form for multi select categories.

{{ Form::open(['role' => 'form', 'method' => 'post', 'route' => 'admin.games.store', 'files' => true]) }}
{{ Form::select('categories[1][]', $platform, null, ['multiple'=>true, 'class' => 'form-control']) }}
{{ Form::select('categories[2][]', $genre, null, ['multiple'=>true, 'class' => 'form-control']) }}
{{ Form::select('categories[3][]', $developer, null, ['multiple'=>true, 'class' => 'form-control']) }}
{{ Form::close() }}

I defined $developer, $genre and $platform in my controller, this is basically a list of categories under specific id.

$platform = Category::->where('type', '=', 1)->lists('name', 'id');

So this returns an array of all categories for a view.

| name      | id |
| Windows |  1 |
| Linux       |  2 |
| MacOS    |  3 |

So this all works fine i have my select forms working fine with categories i specified and upon submit i get an array of values, as array can't be saved i serialized that very simple with:


And i have serialized data in my database, i know someone would say it's not a good way if i need to search etc... i will not be able to use that field. But for me i need only to store id's of selected categories and query them all together at once. so this is good for me.

But now i have a problem, i am not finding a way to get that data when i edit a page.

I use Route::controller so you know work flow how the pages are updated, stored, edited, created... And since form can automatically populate the fields using Form::model i used that before and it's very nice feature. But i don't know how to populate the fields now when i edit the page.

Here is a form on my edit.blade.php

{{ Form::model($game, ['role' => 'form', 'method' => 'PUT', 'route' => ['admin.games.update', $game->id ], 'files' => true]) }}
{{ Form::select('categories[1][]', $platform, null, ['multiple'=>true, 'class' => 'form-control']) }}
{{ Form::select('categories[2][]', $genre, null, ['multiple'=>true, 'class' => 'form-control']) }}
{{ Form::select('categories[3][]', $developer, null, ['multiple'=>true, 'class' => 'form-control']) }}
{{ Form::close() }}

So how do i get that serialized data and populate the select fields with selected categories when editing a page using Form::model. Any ideas, i searched on net and no answers.

I have to mention i use laravel 4.2

04 Feb
4 years ago

lonerunner left a reply on How To Use Laravel Auth::user() Outside Laravel And Pass Data In Custom Php?

This doesn't help, i don't have an app.php in bootstrap folder, and i also don't have Illuminate\Contracts\Http\Kernel anywhere in laravel. it's probably difference between versions. i use Laravel Framework version 4.2.16

03 Feb
4 years ago

lonerunner started a new conversation How To Use Laravel Auth::user() Outside Laravel And Pass Data In Custom Php?

I am trying to implement simogeo filemanager into laravel and using it in combination with tinymce i will use it without tinymce also but that's not the problem.

I have already configured setup and installed all, and it works fine so far, but last one step is to make sure that only authorized users can call filemanager and upload files, and also there is an option to filemanager to have user specific folders. For that i will have to pass Auth::user() from laravel and check if user is loged in, and also if i use Auth::user()->username i would be able to have user specific folders.

Is there a way to pass Auth::user() for outside script from laravel?

20 Jan
4 years ago

lonerunner left a reply on What's The Way To Make Custom Validator Rules And Where To Put What File?

Mhm i have a little bit better understanding but still not quite clear what goes where, so ill try with the code in following way.

I will put the error message inside app/lang/en/validator.php

And create new file inside app/Providers/Validation/CustomValidationProvider.php

Than inside app/config/app.php under providers array setup new provider "Providers\Validation\CustomValidationProvider"

Than back in CustomValidationProvider.php file as i understand i should make namespace, used provider and class so the code should be

namespace Providers\Validation;

use Illuminate\Validation\Validator

class CustomValidator extends Validator   {
        $this->app['validator']->resolver(function($translator, $data, $rules, $messages)
            return new CustomValidator($translator, $data, $rules, $messages);

I am not sure if this will work or not, i didn't tested it, these are just assumptions i think will work as i gathered informations from documentations online. Though i am still not sure if this is correct should i make new file CustomValidator.php and input my validation functions in there. Basically i don't know where to put the code that i posted in my first message in this case.

And @pmall i know there is url validation rule in laravel but that just checks if input is formated as an url as i understand. I need something to check for specific url like in my example checkurl:youtube.com and this validate only if website is youtube.com. This doesn't exist in laravel as i have read. Anyway there are three more fields for now that i need custom validation.

lonerunner started a new conversation What's The Way To Make Custom Validator Rules And Where To Put What File?

I am in need of making few custom validation rules for few form inputs and i have googled many pages but there is no explanation on any of them how to unify and have a clean code of custom validation rules. I have tested with for example

Validator::extend('checkurl', function($attribute, $value, $parameters) {
    $url = parse_url($value, PHP_URL_HOST);
    return $url == $parameters[0];

Putting it in routes.php file and it works, but now it shows a type of error message like validation.checkurl

And if i have multiple validation rules the routes.php will get a bit crowded. I have 4 custom validation rules now.

Is there a way that i put the validation rules in some file like /app/validators/myvalidators.php and register it and where do i post custom messages for validators?

12 Jan
4 years ago

lonerunner left a reply on What's Good Approach To Get Values From Second Table That Match First Table While List All Rows?

I don't know which one answer to select because both are kinda right, although i had to use my own logic to get final solution. I have searched a bit for hasMany and belongsTo and came up with a solution, i had to change a bit namings in my database, for me to be easier to understand things what is what and at the end i came up with this.

Table users


And user_roles table


So i edited User model with this

    public function role() {
        return $this->belongsTo('UserRole', 'role_level', 'level');

And created new UserRole model with this

 class UserRole extends Eloquent {
    //maybe i should name a function user_roles()
     public function users()
         return $this->hasMany('User', 'level', 'role_level');

And in the end in my controller i can use example

    public function getListAllUsers() {
        $users = User::paginate(30);
        return View::make('admin.users')
            ->with('users', $users);

And of course in my view i can list foreach user and show user role and role name something like this

                @foreach($users as $user)
                        <td>{{ $user->username }}</td>
                        <td>{{ $user->first_name }} {{ $user->last_name }}</td>
                        <td>{{ $user->email }}</td>
                        <td>{{ $user->role->role_name }}</td>

Works like a charm. I very much like how things are simple and fast done in laravel.

11 Jan
4 years ago

lonerunner started a new conversation What's Good Approach To Get Values From Second Table That Match First Table While List All Rows?

I am building simple users list but i am also implementing user roles and i have 2 different tables for that.

One is roles and another is users.

The roles table contains:

Name -> role_level

So the name and corresponding level of the roles would be

Admin -> 1 Moderator -> 5 Editor -> 10 Registered -> 20

And users table with usual users fields: name, surname, username and one field "role" which corresponds to the "role_level" of roles database.

So now i would want to list all the users and display their info with role names

So i have function

public function getAllUsers {
    $users = User::paginate(30); //to limit per 30 users per page
    return View::make('users')->wity('users', $users);

and inside my users.blade.php page i list all the users with @foreach

Now, i know 2 ways right now which both might be actually slow and happens to me to be slow using on custom php built website. One is to use DB::table('roles') and match role_level with role from users table and display the name of matched role_level. And other is to use DB::table()->leftJoin, or DB::table()->join

Would you use some other way to get the data, and what would be the best approach by your thoughts?

22 Dec
4 years ago

lonerunner left a reply on Does Artisan Have A Model Command Or Do I Need To Make It Manually?

Thanks, nice, this helps me out. Just one more question, in default generated user model file i have a few files included at the top of the file before the class for example use Illuminate\Auth\UserTrait; do i need to include those on every model or those are like model specific files so are only used by specific models?

lonerunner started a new conversation Does Artisan Have A Model Command Or Do I Need To Make It Manually?

I am just in the learning of laravel and i gave my self a job to make like blog type thingy.

It looks very simple though, i need a table with posts, a model to list all posts and controller for edit, save, delete, make new posts, am i right?

But from a few tutorials i watched here on laracast and from documentations there is no universal way of making model in artisan.

So is there any base type of model to make via artisan or some sort of for a start or do i need to start from scratch.

Can i just copy user model and edit it my way for blog posts?

Sorry if the questions are stupid but it's my 3rd day of laravel learning :)