How to explode multi sms number on laravel 5.2?
public function store(Request $request)
{
$mes = new Outbox();
$mes->DestinationNumber = $request->input('DestinationNumber');
$explode = explode(' ',$mes->DestinationNumber);
return $explode;
}
This is not a Laravel related question.
Find the documentation from the PHP web and use your logic.
It depends how you have $mes->DestinationNumber stored and how you want them to return from your function.
// CSV to array
$result= explode(',', $mes->DestinationNumber);
// array to CSV
$result= implode(',', $mes->DestinationNumber);
Check before you convert and return your result:
var_dump($mes->DestinationNumber);
// your logic here ..
var_dump($result);exit;
Related
My problem is that when I send a post from an rfid card via esp8266, the data is an rfid number, but the data can't appear because the code I gave has not been written into Laravel.
This PHP code :
<?php
if(isset($_POST['uid'])) {
$uid = $_POST["uid"];
$sql = mysqli_query($dbconnect, "INSERT INTO tb_entry VALUES ('$uid')");
}
?>
How can I write this code into Laravel controller?
it should be like this
if ($request->has('uid')) {
DB::table('tb_entry')->insert([
'uuid' => $request->uuid
]);
}
create a controller: php artisan make:controller MyController
add a method to the controller like public function test(Request $request) {}
rewrite your code a little bit and pasted in:
public function test(Request $request) {
if (null !== $request->post('uid')) {
$uid = $request->post('uid');
// Note: you can use Laravel model instead plain mysqli query
// ** Beware of SQL injection vulnerabilities! **
$sql = mysqli_query($dbconnect, "INSERT INTO tb_entry VALUES ('$uid')");
}
}
When I use without paginate, the Voyager Translatable trait works fine.
$data = Post::where('status', 1)->get()->translate();
But, when I change it to paginate:
$data = Post::where('status', 1)->paginate(15)->translate();
in view:
$data->links()
then it gives an error in blade view:
Method TCG\Voyager\Translator\Collection::links does not exist
How can I solve this issue?
i did it that:
public function getTranslated(Builder $query, string $lang) : array {
$data = $query->paginate();
$dataArray = $data->toArray();
$translatedData = $data->translate($lang);
$dataArray['data'] = $translatedData->toArray();
return $dataArray;
}
How I can check the selected elements that I pass from front end using Log::info? I tried using this but I dont know how to check the result, or maybe the code is wrong?
public function filterQuery(Request $request){
$name= $request->name;
$age= $request->age;
Log::info('Showing user profile for user: '.$name);
$query = user::query();
if(!empty($request->name)){
$query->where('name',$name);
}
So I'm data from a multi-page form, the data is stored like this.
I'm using this tutorial https://www.5balloons.info/multi-page-step-form-in-laravel-with-validation/
public function store(Request $request)
{
$user = $request->session()->get('user');
$user->save();
return redirect('/home');
}
That works fine. But how do I add additional data manually using the arrow function? For example, I need to set a status, the ip address, ect. Something like 'status' => 1
Assuming this is the only place you want to add these values to users, you could just add the values after you got it from the session:
public function store(Request $request)
{
$user = $request->session()->get('user');
$user->ip_address = '127.0.0.1';
$user->status = 1;
$user->save();
return redirect('/home');
}
you can add addition data like:
if your $user is laravel object then
$user->setAttribute('status', '1');
or $user if array then
$user['status']=1;
I'm trying to attach the currently logged in user to this request, so that I can save it in the database. Can someone point me in the right direction, please?
public function store(CreateLeadStatusRequest $request)
{
$input = $request->all();
$leadStatus = $this->leadStatusRepository->create($input);
Flash::success('Lead Status saved successfully.');
return redirect(route('lead-statuses.index'));
}
So, I have come up with the following using array_merge, but there must be a better way, surely?
public function store(CreateLeadStatusRequest $request)
{
$input = $request->all();
$userDetails = array('created_by' => Auth::user()->id, 'modified_by' => Auth::user()->id);
$merged_array = array_merge($input, $userDetails);
$leadStatus = $this->leadStatusRepository->create($merged_array);
Flash::success('Lead Status saved successfully.');
return redirect(route('lead-statuses.index'));
}
So you can use Auth Facade to get information of currently logged user.
For Laravel 5 - 5.1
\Auth::user() \\It will give you nice json of current authenticated user
For Laravel 5.2 to latest
\Auth::guard('guard_name')->user() \\Result is same
In laravel 5.2, there is new feature called Multi-Authentication which can help you to use multiple tables for multiple authentication out of the box that is why the guard('guard_name') function is use to get authenticated user.
This is the best approach to handle these type of scenario instead of attaching or joining.
public function store(CreateLeadStatusRequest $request)
{
$input = $request->all();
$userDetails = \Auth::user(); //Or \Auth::guard('guard_name')->user()
$leadStatus = $this->leadStatusRepository->create($input);
Flash::success('Lead Status saved successfully.');
return redirect(route('lead-statuses.index'));
}
Hope this helps.