Where and how is this data being changed? - laravel-4

The following code works fine, except that there is some "cleaning up" of the data that is taking place in one instance and not the other that I can't decipher.
I have a table (clientdocs) with a field 'from' that contains string data in the format:
Richard Robinson <richard#gmail.com>
In my controller, I have code that builds an array for a dropdown from this table:
// get clients
$sender_sel = array('Any Sender');
$senders = Clientdoc::orderBy('from', 'ASC')
->distinct()
->get( array('from') );
foreach($senders as $sender) {
$sender_sel[] = $sender->from;
}
I also retrieve all the data from the table and pass it to the view (along with the above array and other stuff):
return View::make('clientdocs/index')
->with('date_sel', $date_sel)
->with('sender_sel', $sender_sel)
->with('docs', Clientdoc::orderBy('date_emailed', 'ASC')->get());
Now, in my view:
I use $sender_sel as:
{{ Form::select('from', $sender_sel, '', array(
'class' => 'form-control'
)) }}
and it displays as expected:
"Richard Robinson <richard#gmail.com>"
and I also use data from the 2nd query (docs object):
<table class="table table-striped table-hover">
<tr>
<th>Date</th>
<th>From</th>
<th>Type</th>
</tr>
#foreach ($docs as $doc)
<?php $detail_url = 'clientdocs/' . $doc->id . '/edit' ; ?>
<tr>
<td>{{ $doc->from }}</td>
</tr>
#endforeach
</table>
Here's the kicker: $docs->from displays as
"Richard Robinson", without the "<richard#gmail.com>"
Any ideas why?

View source. It's still there, but < and > are special characters in HTML (as they're used in HTML tags).
Using triple brackets escapes output in Blade, so {{{ $doc->from }}} will fix it by turning it into < and >.

Related

Can we Put 3 database data in One Table

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

How to showing data on blade with pass through 2 table FK

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.

Passing multiple variables in Controllers

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');

Laravel Building Referral System- Cant display Users in Blade

I Building an Affiliate System for my Users. Registration with ID works fine and save all correct in my DB, but i cant see any Referrals that use my URL ID for Registration in my Example Blade.
Any one cant find the Error?
Controller:
$referal_id = $user->id;
$referer_id = $request['referal_id'];
$referalUserData = [
'referer_id' => $referer_id,
'referal_id' => $referal_id,
];
$insert = ReferralUser::insert($referalUserData);
Blade:
<tr>
<th>#</th>
<th>User Id#</th>
<th>User Name</th>
<th>Registration Time</th>
</tr>
</thead>
<tbody>
#if(!empty($referalUser))
#foreach($referalUser as $referData)
<tr>
<th scope="row">{{$referData->id}}</th>
<td>{{$referData->referal_id}}</td>
<td>#for($i=0;$i<count($referData['names']);$i++) {{$referData['names'][$i]['name']}} #endfor
</td>
<td> {{$referData->created_at}}<br/> <span class="label label-primary">
{{Carbon\Carbon::createFromTimestamp(strtotime($referData->created_at))->diffForHumans()}} </span> </td>
</tr>
#endforeach
#else
<div class="alert alert-noreferals">
<strong></strong><span>No referrals!</span>
</div><br/><br/>
#endif
Ignore the created_at Timestamp.
Thanks
Did you convert the $request object to an array?
$request['referal_id'];
That looks suspicious. Typically you would use
$request->input('referal_id')
or via dynamic properties
$request->referal_id
To access a given value.
Are you getting an error? Anything in the log files?

Use image path stored in database to display the image in Laravel 5.0

In my ImageController, I've moved an image to a directory and saved the image path in a table in database as,
public function store(Request $request)
{
$new_country = new SelectCountry();
$message = [
'required' => "This field can not be empty",
];
$this->validate($request, [
'country_name' => 'required',
'alternate_title' => 'required',
'country_flag' => 'required',
], $message);
$new_country->country_name = $request->country_name;
$new_country->alternate_title = $request->alternate_title;
if($request->hasfile('country_flag'))
{
$country_flag_image = $request->file('country_flag');
$country_flag_name = $country_flag_image->getClientOriginalName();
$extention = $country_flag_image->getClientOriginalExtension();
$dirpath = public_path('assets/images/country/');
$country_flag_image->move($dirpath,$country_flag_name);
$new_country->country_flag_path = $dirpath.$country_flag_name;
}
$new_country->save();
return redirect()->route('admin.country');
}
Now I want to use the path and display the image along other informations. I've used the following code to return view,
public function select_country()
{
$countries = SelectCountry::all();
return view('auth.select_country')->with('countries',$countries);
}
And in the view, I've used following code to display datas stored in the database,
<table class="table-hover table-responsive container-fluid col-xs-12 col-sm-12">
<thead>
<tr>
<th>Country Name</th>
<th>Alternate Title</th>
<th>Country Flag</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach($countries as $country)
<td>{{ $country->country_name }}</td>
<td>{{ $country->alternate_title }}</td>
<td><img src="{{ $country->country_flag_path }}"></td>
<td>
<a type="button" href="" class="btn btn-warning btn-xs">Update</a>
<a type="button" href="" class="btn btn-danger btn-xs">Delete</a>
</td>
#endforeach
</tbody>
The problem is the image is not displayed while other informations are displayed. The src attribute in img tag is returning path but not directory.
If there is any solution, please tell me. Thanks.
I think your issue lies with where you are setting the storage folder. Laravel with automatically reference the public folder for storage of images etc so there's no need for the public_path function.
Try setting your $dirpath to just $dirpath = "/asset/images/country" as Laravel looks inside public by default. You can then reference it by doing <img src="{{ $country->country_flag_path }}">
Then upload a new image and see what the database has the path set to, hopefully it should be a bit more normal :)
Please note that my original answer of:
Try setting your $dirpath to just $dirpath = "images/country" as Laravel looks inside public by default. You can then reference it by doing <img src="{{ asset($country->country_flag_path) }}">
Should still work as it's how I've always done it :)

Resources