Not sure I understand exactly what is going on here. At first I thought it was a blade issue, now I'm not sure. I can kindof duplicate this in tinker.
I noticed that I was incorrectly showing the current user in my index blade instead of the record owner. As a quick cheat, I added some code to resolve the user_id in the record to display that users name. What I get is "two" user names.
@foreach ($snippets as $snippet)
<tr>
<td><a href="{{ action('SnippetsController@edit', [$snippet->id]) }}">{{$snippet->id}}</a></td>
<td><a href="{{ action('SnippetsController@show', [$snippet->id]) }}">{{$snippet->name}}</a></td>
<td>{{$snippet->status}}</td>
<td>{{$snippet->user_id}} {{App\User::find($snippet->id)->lists('name')}}</td>
<td>{{$snippet->type}}</td>
@endforeach
This displays two user names, the logged in user and the record owner. ["Admin","Debbie"]
$this->user is set in the constructor to the authorized user. Subsequent calls whether I use the facade or instance "adds" the new record to the collection. This happens in tinker too.
Psy Shell v0.6.1 (PHP 7.0.2 — cli) by Justin Hileman
App\User::find(1)->lists('name');
=> Illuminate\Support\Collection {#812
all: [
"Admin",
"Debbie",
],
App\User::find(2)->lists('name');
=> Illuminate\Support\Collection {#811
all: [
"Admin",
"Debbie",
],
App\User::where('id','=',1)->lists('name');
=> Illuminate\Support\Collection {#820
all: [
"Admin",
],
The table is setup for id to be auto increment unique
table->string('type', 24);
$table->enum('status', ['Active','Archived','Dead','Inactive']);
$table->text('notes')->nullable();
$table->string('name', 60);
$table->string('salutation', 60)->nullable();
$table->string('fname', 60)->nullable();
$table->string('lname', 60)->nullable();
$table->string('title', 60)->nullable();
$table->date('birthday')->nullable();
$table->date('anniversary')->nullable();
$table->string('email', 60)->unique();
$table->string('emailhome', 60)->nullable();
$table->string('emailalt1', 60)->nullable();
$table->string('emailalt2', 60)->nullable();
$table->string('emailalt3', 60)->nullable();
$table->string('emailpersonal', 60)->nullable();
$table->string('password', 60);
$table->string('address1', 60)->nullable();
$table->string('address2', 60)->nullable();
$table->string('city', 60)->nullable();
$table->string('state', 60)->nullable();
$table->string('zip', 18)->nullable();
$table->string('phonehome', 18)->nullable();
$table->string('phonecell', 18)->nullable();
$table->string('phonealt', 18)->nullable();
$table->string('fax', 18)->nullable();
$table->rememberToken();
$table->timestamp('lastactivity')->nullable();
$table->timestamp('lastaccoutactivity')->nullable();
$table->timestamps();
});
}
mysql> select id,name from users;
+----+--------+
| id | name |
+----+--------+
| 1 | Admin |
| 2 | Debbie |
+----+--------+
2 rows in set (0.00 sec)
Am I misunderstanding find(), findOrFail(), or is something else going on?