I have 3 table like users , data_users , practice
users : id , name ,dob ,email , etc . . .
data_users : id , user_id , number_exp , etc . .
practice : id , data_user_id , practice_number , etc ....
in 3 tables connect by relation belongsTo and and want to showing this .
i want to show data on table practice :
My controller :
public function show()
{
$practice= Practice::with('data_users')->get();
return view('admin.practice' ,['practice'=>$practice]);
}
my view
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>No Surat</th>
<th>Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
#foreach ($practice as $i)
<tr>
<th scope="row">1</th>
<td>{{ $i->data_users->users->name}}</td>//i want to show name but i cant show this
<td>{{ $i->practice_number}}</td>
<td>{{ $i->practice_date}}</td>
<td>{{ $i->status}}</td>
</tr>
#endforeach
</tbody>
</table>
i have problem to showing Data 'NAME' form table users , and i just can showing id from data_users
but still error Trying to Get property
try this:
public function show()
{
$practice= Practice::with('data_users', 'data_users.users')->get();
return view('admin.practice' ,['practice'=>$practice]);
}
You are returning $practice collection from controller, trying to foreach $riwayat collection.
Related
Im trying to make a list with game developers, and when you click on one of them you can see the games they have made. I only dont know how to get further....
This is what i have now:
Index.blade.php:
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Naam</th>
<th scope="col">Opgericht in:</th>
</tr>
</thead>
<tbody>
#foreach($gamedevs as $gamedev)
<tr>
<td>{{ $gamedev['id'] }} </td>
<td>{{ $gamedev['naam'] }}</td>
<td>{{ $gamedev['opgericht'] }}</td>
</tr>
#endforeach
</tbody>
I already tried some methods like these:
href="{{route('games.show', ['id'=>$gamedev->id])}}
and
href="/games/{{$gamedev['id']}}
listcontroller.php
public function index()
{
$gamedevs = Gamedevs::all();
return view("index", [ 'gamedevs' => $gamedevs]);
}
public function show(Gamedevs $gamedevs)
{
$gamedevs = Gamedevs::where($gamedevs)->first();
return view('pages.games.show')->with('Gamedevs',$gamedevs);
}
Never did this before.. so hope im on the right way :)
Laravel controller methods like show will use service container to resolve all the parameters you define there. Since you define a model, laravel will automatically find the one corresponding with explicit model binding.
So you wont have to write another query to show your Gamedev:
public function show(Gamedevs $gamedevs)
{
return view('pages.games.show')->with('Gamedevs',$gamedevs);
}
Sample route in web.php
Route::get('/games/{dev_id}','listController#show');
Sample Method in your listController.php
public function show($gamedevs)
{
#let's say your $gamedevs is your devs id so target their id's
$devs = Gamedevs::where('id',$gamedevs)->first();
return view('pages.games.show')->with([
'Gamedevs'=>$devs
]);
}
In your view
href="/games/{{$Gamedevs->id}}
I am writing a function in laravel 5.8 in which I want to get sum of the user amount that lies within my selected range, I am using the two input fields in view which they get the price range "T0 and From" e.g if the user enters 100 and 1000, it should show the list of the users who has amount > 100 and amount < 1000. The problem is there are multiple records of the same users as shown below in the table.
I want to sum the amount of the users and show the user if their amount is within range
table name= deposits
<table>
<thead>
<tr>
<th>id</th>
<th>user_id</th>
<th>name</th>
<th>amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>12</td>
<td>ali</td>
<td>100</td>
</tr>
<tr>
<td>2</td>
<td>12</td>
<td>ali</td>
<td>800</td>
</tr>
<tr>
<td>3</td>
<td>12</td>
<td>ali</td>
<td>50</td>
</tr>
<tr>
<td>4</td>
<td>15</td>
<td>khan</td>
<td>1100</td>
</tr>
<tr>
<td>6</td>
<td>9</td>
<td>james</td>
<td>850</td>
</tr>
<tr>
<td>7</td>
<td>9</td>
<td>james</td>
<td>90</td>
</tr>
</tbody>
</table>
This behavior of your query is correct, to get what you need it is necessary to work on the query.
Assuming this fields in your deposits table: id, user_id, name, amount in according with data showing in the table.
You need to sum the amount grouping by user_id
Example query:
$deposit = Deposits::select(
'id',
'user_id',
'name',
'sum(amount)',
)->whereBetween('amount', [100, 1000])
->groupBy('user_id')->get();
DB::table('deposits')
->selectRaw('user_id, SUM(amount) as total_amount')
->where('amount', '>', '100')
->where('amount', '<', '1000')
->groupBy('user_id')
->get();
Result is:
[
{
"user_id":9,
"total_amount":850
},
{
"user_id":12,
"total_amount":800
}
]
app('db')
->table('users')
->select('name')
->selectRaw("SUM(amount) as total_amounts")
->havingBetween('total_amounts', [ 100, 1000 ])
->groupBy('user_id')
->get();
You can use the raw query for the sum per user and use the having between for the sum of amounts.
I am self learner and stuck at one point. I don't know is that possible or not. Please refer image of data get in array.
I have 3 database table "animalsell", "dairyincomes" and "othersell". I sucessfully able to get required data from this.
Now I want to put the same in one table in blade file (refer table image)
Controller file where i collect the data
$fiveincomedata = Dairyincome::select(
DB::raw('DATE_FORMAT(milksaledate, "%M %Y") as "month_name",SUM(totalamount) as "totalamount", max(milksaledate) as milksaledate')
)
->whereBetween('milksaledate', [Carbon::now()->subMonth(6), Carbon::now()->endOfMonth()])
->groupBy('month_name')
->orderBy('milksaledate', 'desc')
->get()->toArray();
// Income from Animal Sell
$fiveanimalselldata = Animalsell::select(
DB::raw('DATE_FORMAT(selldate, "%M %Y") as "month_name",SUM(totalamount) as "totalamount", max(selldate) as selldate')
)
->whereBetween('selldate', [Carbon::now()->subMonth(6), Carbon::now()->endOfMonth()])
->groupBy('month_name')
->orderBy('selldate', 'desc')
->get()->toArray();
// Income from Other Sell
$fiveotherselldata = Othersell::select(
DB::raw('DATE_FORMAT(saledate, "%M %Y") as "month_name",SUM(totalamount) as "totalamount", max(saledate) as saledate')
)
->whereBetween('saledate', [Carbon::now()->subMonth(6), Carbon::now()->endOfMonth()])
->groupBy('month_name')
->orderBy('saledate', 'desc')
->get()->toArray();
Blade File
<div class="card-body">
<table id="incometable" class="table m-0 table table-bordered table-hover table" style="width:100%">
<thead>
<tr>
<th>Date</th>
<th>Amount (Milk Sale)</th>
<th>Amount (Animal Sale)</th>
<th>Amount (Other Sale)</th>
<th>Total Amount </th>
</tr>
</thead>
<tbody>
#foreach ($fiveincomedata as $fivei )
<tr>
<td>{{ $fivei->month_name }}</td>
<td>{{$fivei->totalamount}}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
Hope i explain my problem clearly and thanks for help in advance.
$a1=array("red","green");
$a2=array("blue","yellow");
array_merge($a1,$a2);
or
push the data into a common array.
You can use the merge() function.
For example:
$fiveincomedata = Dairyincome::all();
$fiveanimalselldata = Animalsell::all();
$fiveotherselldata = Othersell::all();
$merged = $fiveincomedata->merge($fiveanimalselldata);
$merged = $merged->merge($fiveotherselldata);
$array = $merged->toArray();
More information: https://laravel.com/docs/9.x/collections#method-merge
I am trying to add an update table on a show blade for a Laravel project.
The idea being if someone is paid owed subs, they can be check off on the roll.
I can pass the roll.id into the Controller, however this is a member view so I need to grab the roll.member_id of the roll.id record and pass this into the redirect to show the updated member page
Here is the html table
<table class="table">
<thead class = 'text-primary'>
<th class="text-center">Date</th>
<th></th>
</thead>
<tbody>
#foreach ($member->outstanding as $o)
<tr>
<td class="text-center">{{$o->roll_id}}</td>
<td class="text-center"><i class="material-icons">done</i></td>
</tr>
#endforeach
</tbody>
</table>
This is the RollController#updateRoll
public function updateRoll($id){
$o = Roll::find($id);
if ($o != null)
{
$o->status = "C";
$o->save();
return redirect(action('MembersController#show'))->with ('success', 'Member Present');
}
return redirect(action('MembersController#index'));
}
So I would like to add the Member_id into the
return redirect(action('MembersController#show'))->with ('success', 'Member Present');
So I am taken back to the member show blade.
Have you tried passing the ID to the action, same as in your blade view?
For example:
return redirect(action('MembersController#show', $o->member_id))
->with ('success', 'Member Present');
In my laravel 5.7/ blade / jQuery v3.3.1 / Bootstrap v4.1.2 app
I use "yajra/laravel-datatables-oracle": "~8.0" library
and when I need to change class of some rows depending on value of some field I do :
return Datatables
::of($votesCollection)
->setRowClass(function ($vote) {
return $vote->status == 'N' ? ' row_new_status' : ($vote->status == 'I' ? 'row_inactive_status' : '');
})
It works ok, but I did not find any similar methods for columns. Are there ? Can it be implemented in some way ?
UPDATED # 1:
In my blade file I define header of the table :
<div class="table-responsive">
<table class="table table-bordered table-striped text-primary" id="get-warehouse-dt-listing-table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Location</th>
<th>Level count</th>
<th>Created At</th>
<th>Updated At</th>
<th></th>
<th></th>
</tr>
</thead>
</table>
</div>
but not generated rows.
Or can I define it in blade? Please example, if yes.
Thanks!