I'd like to get a specific array data from an array I've get from this code :
$user = $request->instance()->query('user');
var_dump($user);exit;
And the result is :
array(1) { ["user"]=> object(App\Models\User)#332 (27) {
["fillable":protected]=> array(5) { [0]=> string(4) "name" [1]=>
string(8) "username" [2]=> string(5) "email" [3]=> string(8)
"password" [4]=> string(5) "token" } ["hidden":protected]=> array(2) {
[0]=> string(8) "password" [1]=> string(14) "remember_token" }
["casts":protected]=> array(1) { ["email_verified_at"]=> string(8)
"datetime" } ["connection":protected]=> string(5) "mysql"
["table":protected]=> string(5) "users" ["primaryKey":protected]=>
string(2) "id" ["keyType":protected]=> string(3) "int"
["incrementing"]=> bool(true) ["with":protected]=> array(0) { }
["withCount":protected]=> array(0) { } ["perPage":protected]=> int(15)
["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false)
["attributes":protected]=> array(15) { ["id"]=> int(3) ["name"]=>
string(14) "Manchesteriyah" ["username"]=> string(14) "manchesteriyah"
["email"]=> string(24) "manchesteriyah#gmail.com" ["facebook"]=>
string(37) "https://web.facebook.com/xkionna" ["phone"]=> NULL
["email_verified_at"]=> NULL ["password"]=> string(60)
"$2y$10$IrqHE1JfyH0bJ0XD/Hjy.efLg95y/buTIir0PuXcOqDb1yCSS69Oe"
["image"]=> NULL ["description"]=> NULL ["role"]=> string(1) "1"
["token"]=> string(20) "ymsJxEtFnxdPBWYwlYFw" ["member_expiration"]=>
string(19) "2019-07-08 20:33:29" ["created_at"]=> string(19)
"2019-06-08 20:30:25" ["updated_at"]=> string(19) "2019-06-08
20:33:29" } ["original":protected]=> array(15) { ["id"]=> int(3)
["name"]=> string(14) "Manchesteriyah" ["username"]=> string(14)
"manchesteriyah" ["email"]=> string(24) "manchesteriyah#gmail.com"
["facebook"]=> string(37) "https://web.facebook.com/xkionna"
["phone"]=> NULL ["email_verified_at"]=> NULL ["password"]=>
string(60)
"$2y$10$IrqHE1JfyH0bJ0XD/Hjy.efLg95y/buTIir0PuXcOqDb1yCSS69Oe"
["image"]=> NULL ["description"]=> NULL ["role"]=> string(1) "1"
["token"]=> string(20) "ymsJxEtFnxdPBWYwlYFw" ["member_expiration"]=>
string(19) "2019-07-08 20:33:29" ["created_at"]=> string(19)
"2019-06-08 20:30:25" ["updated_at"]=> string(19) "2019-06-08
20:33:29" } ["changes":protected]=> array(0) { } ["dates":protected]=>
array(0) { } ["dateFormat":protected]=> NULL ["appends":protected]=>
array(0) { } ["dispatchesEvents":protected]=> array(0) { }
["observables":protected]=> array(0) { } ["relations":protected]=>
array(0) { } ["touches":protected]=> array(0) { } ["timestamps"]=>
bool(true) ["visible":protected]=> array(0) { }
["guarded":protected]=> array(1) { [0]=> string(1) "*" }
["rememberTokenName":protected]=> string(14) "remember_token" } }
What I'd like to get is the username value, I've tried some solution like this :
$user->username
but it give me error like this :
Trying to get property 'username' of non-object
How to fix this? Thanks for attention.
The $user variable seems to be holding an array containing 1 element, not the User itself. You must first retrieve the User object from the array and then access the username attribute.
$user = $request->instance()->query('user')['user'];
var_dump($user->username); exit;
Related
The below line returns all record from two tables, because I added a relationship for these two tables.
$allmarketers = ProductStock::whereRaw('MONTH(created_at) = ?',[$currentMonth])->get();
Now I want to loop through the records in the view and display the records from two tables for each user. I forgot how to achieve this.
I tried
#foreach($allmarketers as $item)
But how can I get the values of both tables inside this loop?
Var_dump
n)#601 (1) { ["items":protected]=> array(3) { [0]=> object(App\ProductStock)#602 (26) { ["table":protected]=> string(14) "product_stocks" ["fillable":protected]=> array(5) { [0]=> string(8) "marketer" [1]=> string(6) "target" [2]=> string(6) "_token" [3]=> string(10) "updated_at" [4]=> string(10) "created_at" } ["connection":protected]=> string(5) "mysql" ["primaryKey":protected]=> string(2) "id" ["keyType":protected]=> string(3) "int" ["incrementing"]=> bool(true) ["with":protected]=> array(0) { } ["withCount":protected]=> array(0) { } ["perPage":protected]=> int(15) ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) ["attributes":protected]=> array(9) { ["id"]=> int(97) ["user_id"]=> int(70) ["marketer"]=> string(18) "Samson Samson | 70" ["target"]=> string(3) "100" ["_token"]=> NULL ["status"]=> int(1) ["vehicle"]=> string(10) "Unassigned" ["created_at"]=> string(19) "2020-01-07 13:11:47" ["updated_at"]=> string(19) "2020-01-07 13:11:47" } ["original":protected]=> array(9) { ["id"]=> int(97) ["user_id"]=> int(70) ["marketer"]=> string(18) "Samson Samson | 70" ["target"]=> string(3) "100" ["_token"]=> NULL ["status"]=> int(1) ["vehicle"]=> string(10) "Unassigned" ["created_at"]=> string(19) "2020-01-07 13:11:47" ["updated_at"]=> string(19) "2020-01-07 13:11:47" } ["changes":protected]=> array(0) { } ["casts":protected]=> array(0) { } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["appends":protected]=> array(0) { } ["dispatchesEvents":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["relations":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["timestamps"]=> bool(true) ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } } [1]=> object(App\ProductStock)#603 (26) { ["table":protected]=> string(14) "product_stocks" ["fillable":protected]=> array(5) { [0]=> string(8) "marketer" [1]=> string(6) "target" [2]=> string(6) "_token" [3]=> string(10) "updated_at" [4]=> string(10) "created_at" } ["connection":protected]=> string(5) "mysql" ["primaryKey":protected]=> string(2) "id" ["keyType":protected]=> string(3) "int" ["incrementing"]=> bool(true) ["with":protected]=> array(0) { } ["withCount":protected]=> array(0) { } ["perPage":protected]=> int(15) ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) ["attributes":protected]=> array(9) { ["id"]=> int(98) ["user_id"]=> int(72) ["marketer"]=> string(22) "Emmanuel Increase | 72" ["target"]=> string(3) "150" ["_token"]=> NULL ["status"]=> int(1) ["vehicle"]=> string(10) "Unassigned" ["created_at"]=> string(19) "2020-01-07 13:11:47" ["updated_at"]=> string(19) "2020-01-07 13:11:47" } ["original":protected]=> array(9) { ["id"]=> int(98) ["user_id"]=> int(72) ["marketer"]=> string(22) "Emmanuel Increase | 72" ["target"]=> string(3) "150" ["_token"]=> NULL ["status"]=> int(1) ["vehicle"]=> string(10) "Unassigned" ["created_at"]=> string(19) "2020-01-07 13:11:47" ["updated_at"]=> string(19) "2020-01-07 13:11:47" } ["changes":protected]=> array(0) { } ["casts":protected]=> array(0) { } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["appends":protected]=> array(0) { } ["dispatchesEvents":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["relations":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["timestamps"]=> bool(true) ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } } [2]=> object(App\ProductStock)#604 (26) { ["table":protected]=> string(14) "product_stocks" ["fillable":protected]=> array(5) { [0]=> string(8) "marketer" [1]=> string(6) "target" [2]=> string(6) "_token" [3]=> string(10) "updated_at" [4]=> string(10) "created_at" } ["connection":protected]=> string(5) "mysql" ["primaryKey":protected]=> string(2) "id" ["keyType":protected]=> string(3) "int" ["incrementing"]=> bool(true) ["with":protected]=> array(0) { } ["withCount":protected]=> array(0) { } ["perPage":protected]=> int(15) ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) ["attributes":protected]=> array(9) { ["id"]=> int(99) ["user_id"]=> int(73) ["marketer"]=> string(18) "Timothy Kukah | 73" ["target"]=> string(3) "200" ["_token"]=> NULL ["status"]=> int(1) ["vehicle"]=> string(10) "Unassigned" ["created_at"]=> string(19) "2020-01-07 13:11:47" ["updated_at"]=> string(19) "2020-01-07 13:11:47" } ["original":protected]=> array(9) { ["id"]=> int(99) ["user_id"]=> int(73) ["marketer"]=> string(18) "Timothy Kukah | 73" ["target"]=> string(3) "200" ["_token"]=> NULL ["status"]=> int(1) ["vehicle"]=> string(10) "Unassigned" ["created_at"]=> string(19) "2020-01-07 13:11:47" ["updated_at"]=> string(19) "2020-01-07 13:11:47" } ["changes":protected]=> array(0) { } ["casts":protected]=> array(0) { } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["appends":protected]=> array(0) { } ["dispatchesEvents":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["relations":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["timestamps"]=> bool(true) ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } } } }
you can use this below. hope it might help you. it's a simple code. I presume you have id column in your DB.
<table class="table is-striped">
#if(count($allmarketers) > 0)
<thead>
<tr>
<th>id</th>
<th>date</th>
</tr>
</thead>
#endif
<tbody>
#foreach ($allmarketers as $item)
<tr>
<td>{{$item->id}}</td>
<td>{{$item->created_at}}</td>
</tr>
#endforeach
</tbody>
</table>
i can't get access to my login auth even if everything was fine until i did a migration refresh to start from 0 testing everything if it was fine.
i created a user but when i try to login it show just error as if my data was incorrect.
public function login(Request $request) {
if($request->isMethod('post')){
$data = $request->input();
if (Auth::attempt(['email'=>$data['email'],'password'=>$data['password']])) {
return redirect('/admin/dashboard');
}else{
return redirect('admin/')->with ('msg_error','Pseudo ou mot de passe invalide');
}
}
return view ('admin.admin_login');
}
My data from PMA
this is my login form
<form id="loginform" class="form-vertical" method="post" action="{{ url('admin') }} ">#csrf
<div class="control-group">
<div class="controls">
<div class="main_input_box">
<span class="add-on bg_lg"><i class="icon-user"> </i></span><input type="email" name="email" placeholder="Utulisateur" />
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<div class="main_input_box">
<span class="add-on bg_ly"><i class="icon-lock"></i></span><input type="password" name="password" placeholder="Mot de Passe" />
</div>
</div>
</div>
<div class="form-actions">
<span class="pull-left">Mot de passe oubliƩ ?</span>
<span class="pull-right"><input type="submit" value="Se connecter" class="btn btn-success" /></span>
</div>
</form>
The user Creation file :
$user = new User;
$user->name = $data['name'];
$user->role = $data['role'];
$user->email = $data['email'];
$user->password = bcrypt($data['password']);
$user->save();
Data from input :
array(3) {
["_token"]=>
string(40) "2h4nA3WuLSlWfpInCH45eUZqtyvHWEg5K7aYWC83"
["email"]=>
string(14) "test#email.com"
["password"]=>
string(6) "000000"
}
and data after using hash check
object(App\User)#266 (27) {
["fillable":protected]=>
array(6) {
[0]=>
string(4) "name"
[1]=>
string(5) "email"
[2]=>
string(5) "level"
[3]=>
string(8) "password"
[4]=>
string(6) "status"
[5]=>
string(15) "activation_code"
}
["hidden":protected]=>
array(2) {
[0]=>
string(8) "password"
[1]=>
string(14) "remember_token"
}
["connection":protected]=>
string(5) "mysql"
["table":protected]=>
NULL
["primaryKey":protected]=>
string(2) "id"
["keyType":protected]=>
string(3) "int"
["incrementing"]=>
bool(true)
["with":protected]=>
array(0) {
}
["withCount":protected]=>
array(0) {
}
["perPage":protected]=>
int(15)
["exists"]=>
bool(true)
["wasRecentlyCreated"]=>
bool(false)
["attributes":protected]=>
array(9) {
["id"]=>
int(1)
["name"]=>
string(5) "Test1"
["role"]=>
string(5) "Admin"
["email"]=>
string(14) "test#email.com"
["email_verified_at"]=>
string(19) "2018-10-21 00:00:00"
["password"]=>
string(60) "$2y$10$1FRa6tZz9Q.NycSVEickte/zBXfLjSlONH0Byiu363bBtQZVXLbwS"
["remember_token"]=>
NULL
["created_at"]=>
string(19) "2018-10-21 11:39:51"
["updated_at"]=>
string(19) "2018-10-21 11:39:51"
}
["original":protected]=>
array(9) {
["id"]=>
int(1)
["name"]=>
string(5) "Test1"
["role"]=>
string(5) "Admin"
["email"]=>
string(14) "test#email.com"
["email_verified_at"]=>
string(19) "2018-10-21 00:00:00"
["password"]=>
string(60) "$2y$10$1FRa6tZz9Q.NycSVEickte/zBXfLjSlONH0Byiu363bBtQZVXLbwS"
["remember_token"]=>
NULL
["created_at"]=>
string(19) "2018-10-21 11:39:51"
["updated_at"]=>
string(19) "2018-10-21 11:39:51"
}
["changes":protected]=>
array(0) {
}
["casts":protected]=>
array(0) {
}
["dates":protected]=>
array(0) {
}
["dateFormat":protected]=>
NULL
["appends":protected]=>
array(0) {
}
["dispatchesEvents":protected]=>
array(0) {
}
["observables":protected]=>
array(0) {
}
["relations":protected]=>
array(0) {
}
["touches":protected]=>
array(0) {
}
["timestamps"]=>
bool(true)
["visible":protected]=>
array(0) {
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["rememberTokenName":protected]=>
string(14) "remember_token"
}
bool(false)
object(App\User)#279 (27) {
["fillable":protected]=>
array(6) {
[0]=>
string(4) "name"
[1]=>
string(5) "email"
[2]=>
string(5) "level"
[3]=>
string(8) "password"
[4]=>
string(6) "status"
[5]=>
string(15) "activation_code"
}
["hidden":protected]=>
array(2) {
[0]=>
string(8) "password"
[1]=>
string(14) "remember_token"
}
["connection":protected]=>
string(5) "mysql"
["table":protected]=>
NULL
["primaryKey":protected]=>
string(2) "id"
["keyType":protected]=>
string(3) "int"
["incrementing"]=>
bool(true)
["with":protected]=>
array(0) {
}
["withCount":protected]=>
array(0) {
}
["perPage":protected]=>
int(15)
["exists"]=>
bool(true)
["wasRecentlyCreated"]=>
bool(false)
["attributes":protected]=>
array(9) {
["id"]=>
int(1)
["name"]=>
string(5) "Test1"
["role"]=>
string(5) "Admin"
["email"]=>
string(14) "test#email.com"
["email_verified_at"]=>
string(19) "2018-10-21 00:00:00"
["password"]=>
string(60) "$2y$10$1FRa6tZz9Q.NycSVEickte/zBXfLjSlONH0Byiu363bBtQZVXLbwS"
["remember_token"]=>
NULL
["created_at"]=>
string(19) "2018-10-21 11:39:51"
["updated_at"]=>
string(19) "2018-10-21 11:39:51"
}
["original":protected]=>
array(9) {
["id"]=>
int(1)
["name"]=>
string(5) "Test1"
["role"]=>
string(5) "Admin"
["email"]=>
string(14) "test#email.com"
["email_verified_at"]=>
string(19) "2018-10-21 00:00:00"
["password"]=>
string(60) "$2y$10$1FRa6tZz9Q.NycSVEickte/zBXfLjSlONH0Byiu363bBtQZVXLbwS"
["remember_token"]=>
NULL
["created_at"]=>
string(19) "2018-10-21 11:39:51"
["updated_at"]=>
string(19) "2018-10-21 11:39:51"
}
["changes":protected]=>
array(0) {
}
["casts":protected]=>
array(0) {
}
["dates":protected]=>
array(0) {
}
["dateFormat":protected]=>
NULL
["appends":protected]=>
array(0) {
}
["dispatchesEvents":protected]=>
array(0) {
}
["observables":protected]=>
array(0) {
}
["relations":protected]=>
array(0) {
}
["touches":protected]=>
array(0) {
}
["timestamps"]=>
bool(true)
["visible":protected]=>
array(0) {
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["rememberTokenName":protected]=>
string(14) "remember_token"
}
bool(false)
i don't know where is the problem
According to the false return of Hash::check('000000', $user->password);, the password is not a hashed value of 000000 in the database.
You can reset the password with
$user->update(['password' => bcrypt('000000')]);
Bcrypt is a helper function for Hash::make. Using artisan tinker will make this easy as it provides you an interactive console to run commands.
i have put a returned API object response into an array but now i want to access the array data, i get undefined index, this is my code.
$paystack = new Yabacon\Paystack('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$trx = $paystack->transactions(["perPage"=>1, "amount"=>10000, "status"=>"success"]); //RETURNED OBJECT
$array = (array) $trx; //CONVERTED FROM OBJECT TO ARRAY.
When I var_dump( (array) $trx ); i get
array(4) { ["status"]=> bool(true) ["message"]=> string(22) "Transactions retrieved" ["data"]=> array(1) { [0]=> object(stdClass)#21 (22) { ["id"]=> int(901742) ["domain"]=> string(4) "test" ["status"]=> string(7) "success" ["reference"]=> string(13) "58c0e61ca5cce" ["amount"]=> int(10000) ["message"]=> NULL ["gateway_response"]=> string(10) "Successful" ["paid_at"]=> string(24) "2017-03-08T22:48:33.000Z" ["created_at"]=> string(24) "2017-03-08T22:48:11.000Z" ["channel"]=> string(4) "card" ["currency"]=> string(3) "NGN" ["ip_address"]=> string(14) "xxx.xxx.xxx.xxx" ["metadata"]=> object(stdClass)#23 (2) { ["custom_fields"]=> array(1) { [0]=> object(stdClass)#22 (3) { ["display_name"]=> string(13) "Mobile Number" ["variable_name"]=> string(13) "mobile_number" ["value"]=> string(14) "+xxxxxxxxxxxxx" } } ["referrer"]=> string(27) "http://localhost/b/checkout" } ["log"]=> object(stdClass)#24 (9) { ["time_spent"]=> int(24) ["attempts"]=> int(1) ["authentication"]=> NULL ["errors"]=> int(0) ["success"]=> bool(true) ["mobile"]=> bool(false) ["input"]=> array(0) { } ["channel"]=> NULL ["history"]=> array(4) { [0]=> object(stdClass)#25 (3) { ["type"]=> string(5) "input" ["message"]=> string(55) "Filled these fields: card number, card expiry, card cvv" ["time"]=> int(20) } [1]=> object(stdClass)#26 (3) { ["type"]=> string(6) "action" ["message"]=> string(16) "Attempted to pay" ["time"]=> int(20) } [2]=> object(stdClass)#27 (3) { ["type"]=> string(7) "success" ["message"]=> string(17) "Successfully paid" ["time"]=> int(22) } [3]=> object(stdClass)#28 (3) { ["type"]=> string(5) "close" ["message"]=> string(11) "Page closed" ["time"]=> int(24) } } } ["fees"]=> int(150) ["fees_split"]=> NULL ["customer"]=> object(stdClass)#29 (8) { ["id"]=> int(102185) ["first_name"]=> string(0) "" ["last_name"]=> string(0) "" ["email"]=> string(23) "xxxxxxxxxx#gmail.com" ["customer_code"]=> string(19) "CUS_xxxxxxxxxxx" ["phone"]=> string(0) "" ["metadata"]=> NULL ["risk_action"]=> string(7) "default" } ["authorization"]=> object(stdClass)#30 (12) { ["authorization_code"]=> string(15) "AUTH_xxxxxxxxx" ["bin"]=> string(6) "412345" ["last4"]=> string(4) "1381" ["exp_month"]=> string(2) "01" ["exp_year"]=> string(4) "2020" ["channel"]=> string(4) "card" ["card_type"]=> string(4) "visa" ["bank"]=> string(9) "TEST BANK" ["country_code"]=> string(2) "NG" ["brand"]=> string(4) "visa" ["reusable"]=> bool(true) ["signature"]=> string(24) "SIG_xxxxxxxxxxxx" } ["plan"]=> object(stdClass)#31 (0) { } ["subaccount"]=> object(stdClass)#32 (0) { } ["paidAt"]=> string(24) "2017-03-08T22:48:33.000Z" ["createdAt"]=> string(24) "2017-03-08T22:48:11.000Z" } } ["meta"]=> object(stdClass)#33 (6) { ["total"]=> int(6) ["total_volume"]=> int(60000) ["skipped"]=> int(0) ["perPage"]=> string(1) "1" ["page"]=> int(1) ["pageCount"]=> int(6) } }
What I want to do is, I want to get it in this format
$stats = $array['data']['status'];
$order_id = $array['data']['id'];
$transaction_method = $array['data']['channel'];
$currency = $array['data']['currency'];
$reference = $array['data']['reference'];
$final_price = $array['data']['amount'];
$email_send = $array['data']['customer']['email'];
$day_paid = $array['data']['paid_at'];
$referring_page = $array['data']['metadata']['referrer'];
But when i ECHO any variable out e.g i do echo $stats OR echo $order_id i get
Notice: Undefined index: status in C:\xampp\htdocs\b\d\paystackorders.php on line 150
Notice: Undefined index: id in C:\xampp\htdocs\b\d\paystackorders.php on line 151.
How do i go around resolving this.
It needs to be $array['data'][0]['status']
and $array['data'][0]['id']
and so on...
This is because $array['data'] is an array of objects
The best way to go in my opinion is as follows:
$data = $array['data'][0];
And then access what you want :
$status = $data['status'];
$order_id = $data['id'];
$result = User::where('email_add', '=', $username)->first();
Here's what shows up when I use var_dump on $result
object(User)#22 (30) { ["user_id"]=> int(0) ["fname"]=> string(0) "" ["lname"]=> string(0) "" ["mname"]=> string(0) "" ["bdate"]=> string(0) "" ["contact"]=> string(0) "" ["email_add"]=> string(0) "" ["fillable":protected]=> array(6) { [0]=> string(5) "fname" [1]=> string(5) "mname" [2]=> string(5) "lname" [3]=> string(5) "bdate" [4]=> string(7) "contact" [5]=> string(9) "email_add" } ["connection":protected]=> NULL ["table":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["keyType":protected]=> string(3) "int" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(10) { ["user_id"]=> int(33) ["fname"]=> string(6) "Robert" ["lname"]=> string(6) "Marley" ["mname"]=> string(5) "Nesta" ["bdate"]=> string(10) "0000-00-00" ["contact"]=> string(11) "09123847599" ["email_add"]=> string(40) "7c9ac9ca8543dd84f71aa541d422e2a95d3e7450" ["photo"]=> NULL ["created_at"]=> string(19) "2017-01-25 01:03:06" ["updated_at"]=> string(19) "0000-00-00 00:00:00" } ["original":protected]=> array(10) { ["user_id"]=> int(33) ["fname"]=> string(6) "Robert" ["lname"]=> string(6) "Marley" ["mname"]=> string(5) "Nesta" ["bdate"]=> string(10) "0000-00-00" ["contact"]=> string(11) "09123847599" ["email_add"]=> string(40) "7c9ac9ca8543dd84f71aa541d422e2a95d3e7450" ["photo"]=> NULL ["created_at"]=> string(19) "2017-01-25 01:03:06" ["updated_at"]=> string(19) "0000-00-00 00:00:00" } ["relations":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["casts":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) }
Here's what happens when I use foreach to var_dump each $user on the $result
int(0) string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" bool(true) bool(true) bool(true) bool(false)
I've been looking for a solution to this but I don't seem to find one, I was using get() at first but I read somewhere that if I'm expecting only 1 result, I should be using first() but it doesn't change anything. I can't access the Collection..
I've found a solution
This one helped me.
adding ->toArray on my ->first() was the magic, it only returns an array with the exact attributes without the unnecessary object properties.
That's is a kind of what I'm used to see in laravel when I use dd($var); function to see whats in the variable:
{
id: "1",
username: "Muzikman",
email: "matt.paolini#gmail.com",
password: "$2y$10$Sp7k9Fs0DwFSYHTpWrTWquFmXJpkiKfRIHsjYtdEXTvbdOJwv9AtG",
password_confirmation: "",
confirmation_code: "91f0583ed76c95ebf378648d65d0eac7",
remember_token: "bGmdTchXtilBj41FIazkFS3PDZzr1tVKmTFnMkeeSoD7wpW6hoQ07A42plle",
confirmed: "1",
created_at: "2014-10-19 12:17:55",
updated_at: "2014-10-20 15:07:01",
but in my app I have no idea why now I see like this when I dd($var);
object(OrdemServico)#728 (23) { ["guarded":protected]=> array(4) { [0]=> string(10) "updated_at" [1]=> string(10) "created_at" [2]=> string(10) "deleted_at" [3]=> string(2) "id" } ["fillable":protected]=> array(13) { [0]=> string(7) "tipo_id" [1]=> string(10) "cliente_id" [2]=> string(11) "contrato_id" [3]=> string(10) "tecnico_id" [4]=> string(10) "created_by" [5]=> string(10) "updated_by" [6]=> string(13) "data_execucao" [7]=> string(13) "tempo_servico" [8]=> string(18) "tempo_deslocamento" [9]=> string(5) "ativo" [10]=> string(10) "finalizada" [11]=> string(5) "os_id" [12]=> string(6) "visita" } ["dates":protected]=> array(1) { [0]=> string(10) "deleted_at" } ["errors"]=> NULL ["originalAttributes":protected]=> array(0) { } ["autoHydrateEntityFromInput"]=> bool(true) ["connection":protected]=> NULL ["table":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(0) { } ["original":protected]=> array(0) { } ["relations":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["morphClass":protected]=> NULL ["exists"]=> bool(false) }
its all in the same line and hard to read and identify the attributes, how could fix this?
obs that's isnt the same object, I just got any from google in the first one, the second is my actual dd(); and how show the attributes
thx for help!