I have two additional column for login with different tables. So, I used 3 tables for login with output like this:
When I want to use username its simply write it like this {{ Auth::user()->username }} so I get value KASIR WEB. But it not work with kd_lokasi and kd_shift. Where I should register it? Or how I can get kd_lokasi and kd_shift value and paste it on view? Thank you for helping me.
Table :
$kd_lokasi = DB::table("tb_kasir_lokasi")->where("vTampil", 1)->get()
->pluck("nm_lokasi", "kd_lokasi");
$kd_shift = DB::table("tb_kasir_shift")->where("vTampil", 1)->get()
->pluck("nm_shift", "kd_shift");
Related
I am using Laravel and have a table that has columns with spaces. I can't change the names of the columns. I am trying to use Eloquent and have tried many things to get this to work but can't. I thought this would be the answer:
{{$provider->'Entity Type Code'}}
Thanks
You can use {} brackets
{{ $provider->{'Entity Type Code'} }}
Or use another variables
$variable_name = 'Entity Type Code';
{{ $provider->$variable_name }}
I have many to many relationship between an actor and a theater_play.
How to add his stage name when making the connection? I have a table for the actor, a table for theater_play and a table for the connection of many to many call actor_theater_play where I connect the IDs.
My goal is to display John Doe is know for his roles: and then to list Name of Play - Character Name.
In your theatre play relation on your Actor model, make sure you use the ->withPivot() method to specify which pivot fields you want attached with the relation:
public function theaterPlays() {
return hasMany(\App\TheaterPlay::class)->withPivot('stage_name');
}
You will then able able to access in your list (Laravel blade example):
#foreach($actor->theater_plays as $theater_play)
{{ $theater_play->name . ' - ' . $theater_play->stage_name }}
#endforeach
Iam learning laravel.I don't understand how to read multiple data in laravel.
In my Data-table , my value is 1,2,3
my column name is hobby & value is 1,2 . 1 & 2 are related other table, where i stored my hobby name .
suppose ,
id || name
1 || gardening
2 || playing
I want to display
gardening,playing
My controller's Code :-
$interests = DB::table('tbl_interests') ->join('tbl_interest_masters','tbl_interest_masters.interest','=','tbl_interests.id')
->select()
->get();
return view('profile')
->with('interest',$interests);
Don't understand how display data in my view ?
is my code right for read multiple data !!
Note that, i already learn how to read single data with relationship in Laravel.
just remove the select() method from the chain.
$interests = DB::table('tbl_interests')
->join('tbl_interest_masters','tbl_interest_masters.interest','=','tbl_interests.id')
->first();
return view('profile')->with('interest',$interests);
I don't fully understand your question, do you want to return multiple variables?
If so, try this:
return view('YOUR_VIEW', compact('VARIABLE1', 'VARIABLE2'));
If you are using blade, you can use this to display the returned variables:
{{$VARIABLE1}}
Loop through an array:
#foreach($interests as $interest)
{{$interest->name}}
#endforeach
I have two webpages A and B, A has a link button like this
Link
and B is a page about article lists, and has a table with column [#, books_name, author......]
And also, B has a query table to query data, user can input books_name or author_name, then it'll show the data user wants.
My question is, how to modify link in A Page and let it send autocomplete parameter to B?
The result of B's url may be like this
https://{B's path}/?q_author_name={the parameter from Page A}
Hope someone can help me. Thanks!
You can pass the query parameter as second argument to route()
{{ route('to_B', ['q_author_name' => 'Author']) }}
would generate
https://{B's path}?q_author_name=Author
provided you don't have any route parameters in your route definition like
Route::get("{B's path}/{param1}", function () {})->name('to_B');
in that case the first key from the route array would be passed to the param1 making your route as
https://{B's path}/Author
Is it possible to bind a form with a model that has relationships? For example I have a Order model that has a one to many with a Details model. That would save a lot of time with
#foreach($order->details as $detail)
{{ Form::text('product_name', Input::old('product_name') ? Input::old('product_name') : detail->product_name)
#endforeach
For a one-to-one relation it's possible to use something like this:
Form::text('detail[product_name]')
In this case $order->detail->product_name will be populated in the given text box if an instance of Order model is bound to the from using Form::model($order) with the related model Detail but it may not possible for one-to-many because simply there will be a collection and you need a loop.
To complete the answer of #WereWolf..
Make an array of product_name detail_names
Input class allow you to access nested array by dot notation, eg: orders.1.product_name
Don't forget the second argument of Input::old() or Input::get()
is the default value, so you can specify the DB value and avoid conditional test..
.
Form::text('detail_names['.$detail->id.']', Input::old('detail_names.'.$detail->id, $detail->product_name))
In your controller, something like that:
foreach(Input:get('detail_names') as $id => $product_name)
{
//...
}
Hope this will help you to save a bit of time.