how to get parameter value from database using laravel - laravel-4

Im tring to get parameter value from database using laravel,for update a value .
ErrorException (E_UNKNOWN)
Argument 1 passed to Illuminate\Html\FormBuilder::open() must be of the type array, string given, called in
C:\xampp\htdocs\lara1\lara\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 211 and defined (View: C:\xampp\htdocs\lara1\lara\app\views\newsandevents\edit.blade.php)
http://ErrorException
…\vendor\laravel\framework\src\Illuminate\Html\FormBuilder.php95
this is my route code
Route::get('/edit/{id}',array('uses'=>'NewsandeventsController#edit','as' => 'edit'));
Controller.php
public function edit($id)
{
$newsevents=ForumNewsevent::find($id);
return View::make('newsandevents.edit')
->with('newsevents',$newsevents);
}

Related

Type error: ReflectionFunction::__construct() expects parameter 1 to be string, array given

I am new to Laravel. I am getting this Type Error when I change the following routings as below mentioned way.
My previous routing is as below.
web.php
Route::get('/add-teams',[
'as'=>'teams.add',
'uses'=>'TeamsController#addTeams'
]);
It works fine.
But I need to change that as this.
<?php
use App\Http\Controllers\TeamsController;
Route::get('/add-teams', [TeamsController::class, 'addTeams'])->name("teams.add");
Then this error appears. "Type error: ReflectionFunction::__construct() expects parameter 1 to be string, array given"
Please help me to solve this.
TeamsController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Teams;
class TeamsController extends Controller
{
public function saveTeams(Request $request){
$team=new Teams();
$team->team_name=$request->team_name;
$team->description=$request->description;
$team->save();
return back()->with('team_added','Team added successfuly!');
}
}

How do I Binding Data from Resource data into Blade Laravel?

I Have a Controller Like This
public function print(Request $request)
{
$id = explode(',',$request->id);
$data = DeliveryOrder::whereIn('id', $id)->orderBy('created_at', 'desc')->get();
$dataku = DeliveryOrderResource::collection($data);
// return $dataku;
return view('warehouse.printdo', compact('dataku'));
}
If I return the $dataku,..
and then I Will bind the Data into Blade Laravel, but i get an error
Invalid argument supplied for foreach() (View: ,...resources\views\warehouse\printdo.blade.php)
As you provided the screenshot, you have do_details in first array.
what if you don't have do_details in the second array?
You need to check the condition the foreach you're using have data or not.
#if(!empty($row->do_details))
#foreach($row->do_details as $do => $detOrder)
//additional code
#endforeach
#endif

I have two optional parameter second parametere have value and first parameter is empty so how to get second parameter value in controller

I have route like colleges/colleges-in-{area?}-{cities?}-india.
like colleges/colleges-in-virar,thane-maharastra-india. if i pass cities only so can i get cities in controller
In Controller :
$filter_cities = $request->route('area');
$filter_cities = $request->route('cities');
if i pass citiess then it pass in first parameter
You can set variable in your route:
Route::get('colleges/{area}/{city}', 'Controller#myFunction');
In your controller
public function myFunction(Request $request)
{
$area = $request->area;
$city = $request->city;
}
Read documentation here: https://laravel.com/docs/5.8/routing

Laravel 5.4 Internal error: Failed to retrieve the default value with fix

Using Optional Parameters
When i use optional parameters in Laravel 5.4, i get the error internal error: failed to retrieve the default value.
Here is My routes:
Route::group(['middleware' => ['auth','role:SUPER_ADMIN'],'prefix' => 'SWSM-Dashboard'], function () {
Route::get('/', 'HomeController#eventDashboard');
Route::group(['prefix' => '/providers'],function (){
Route::get('create/{providerData?}','ProvidersController#create');
Route::get('delete/{providerId?}','ProvidersController#destroy');
Route::get('/','ProvidersController#index');
});
});
Here is my controller function
public function create($providerData){ dd('Hello'); }
My middleware is just the standard Auth out of the box with Laravel so i'm surprised that this is not working.
I am using php 5.3 so type hinting is not available to me, so i would not normally use it.
The problem is resolved by doing the following to the optional parameter you want to use inside your controller.
public function create($providersData = null)
{
dd($providersData);
}
Now when the route is hit with ..../create/ it will die and dump null but when the route is hit with ..../create/1 the providersData parameter will be set to 1 and die and dump.

Argument 1 passed to Auth\SessionGuard::login() must implement interface Auth\Authenticatable, instance of Http\RedirectResponse given

I'm running Laravel 5.3 and try to modify my registration code to have activation mail feature as referenced in:
https://blog.damirmiladinov.com/laravel/laravel-5.2-email-verification-with-activation-code.html#.WBCTI_l946Q
but i received error:
FatalThrowableError in SessionGuard.php line 441: Type error: Argument
1 passed to Illuminate\Auth\SessionGuard::login() must implement
interface Illuminate\Contracts\Auth\Authenticatable, instance of
Illuminate\Http\RedirectResponse given
here is my create method inRegisterController:
protected function create(array $data){
$user = new RestUser($data);
$user->register();
$this->activation->sendActivationMail($user);
//return redirect('/login')->with('activationStatus', true);
return redirect('/login')->with('status', 'We sent you an activation code. Check your email.');
//return $user;
}
how can i overcome this?
thanks!

Resources