UnexpectedValueException
The Response content must be a string or object implementing __toString(), "object" given.
public function redirectToProvider()
{
/* echo "redirect checking";*/
return Socialite::driver('facebook');
}
public function handleProvidercallback()
{
/* echo "callback coming";*/
$user = Socialite::driver('facebook')->user();
dd($user);
//return $user->name;
}
You need to call the redirect function on the driver
return Socialite::driver('facebook')->redirect();
From the docs
Hope this helps
Related
I am trying to verify webhook signature for GoToWebinar webinar.created event.
Docs: https://developer.goto.com/guides/HowTos/08_HOW_webhooks/
My Middleware (Laravel):
public function handle(Request $request, Closure $next)
{
if (! $this->verifyGoToWebinarWebhookSignature($request)) {
abort(401);
}
return $next($request);
}
private function verifyGoToWebinarWebhookSignature(Request $request):bool
{
return ($request->header('x-webhook-signature') == $this->calculateHmac($request));
}
private function calculateHmac(Request $request):string
{
$secret = '12345';
$signature = $request->header('x-webhook-signature-timestamp');
$payload = json_encode($request->all(), true);
$signaturePayload = $signature . ':' . $payload;
return base64_encode(hash_hmac('sha256', $signaturePayload, $secret, true));
}
The comparison always returns false. Tested on real data. Can't figure out what I did wrong.
Was using the wrong secret, the API allows to create multiple secret keys but if you do not store them there is not way to match them to the x-webhook-secretkey-id in the request header.
My Controller File
public function enquiryExport($id, Request $request)
{
$id[] = $request->explode(",",$id);
return Excel::download(new EnquiryExport($id), 'enquiry.xlsx');
}
and My Export File
protected $id;
function __construct($id) {
$this->id = $id;
}
public function collection()
{
return Enquiry::whereIn('id',explode(",",$this->id))->get();
/* return Enquiry::all(); */
}
Route is like
Route::get('enquiryExport', 'enquiryController#enquiryExport');
Still I am getting this error
"message": "Too few arguments to function App\\Http\\Controllers\\enquiryController::enquiryExport(), 1 passed and exactly 2 expected",
I am checkbox id through AJAX here.
The problems is your Route method.
Get method: the query string (name/value pairs) is sent in the URL of a GET request
Post method: the data sent to the server with POST is stored in the request body of the HTTP request
If you use Get method: try this (I have just read it, not tried)
Route::get('enquiryExport/{id}', 'enquiryController#enquiryExport')->name('enquiryExport');
Submit
If you use Post method: try this (I am used to use this)
Route::post('enquiryExport', 'enquiryController#enquiryExport');
public function enquiryExport(Request $request)
{
return Excel::download(new EnquiryExport($request->input('id')), 'enquiry.xlsx');
}
You can read more here: https://www.w3schools.com/tags/ref_httpmethods.asp
Try this
In controller:
public function enquiryExport(Request $request, $id)
{
return Excel::download(new EnquiryExport($request->id), ''.date('Y-m-d'). '.xlsx', \Maatwebsite\Excel\Excel::XLSX);
}
In Export File:
protected $id;
function __construct($id) {
$this->id = $id;
}
public function collection()
{
return Enquiry::where('id', $this->id)->get();
}
public function map($enquiry): array
{
return [
// $enquiry->WRITE YOUR RECORDS,
// ...
];
}
public function headings(): array
{
return [
//NAME HEADINGS(TITLE) OF YOUR RECORDS IN SIDE SINGLE QUOTATION,
// ...
];
}
In Route:
Route::get('enquiryExport/{id}', 'enquiryController#enquiryExport');
enter image description here
Here is the code and put session-id
public function login(Request $request)
{
$email=$request->email;
$password=$request->password;
$students=Student::where('email','=',$email)
->where('password','=',$password)
->first();
if($students)
{
Session::put('email',$request->email);
Session::put('id',$request->id);
//dd($students);
return redirect()->route('student.dashboard');
}
else
{
Session()->flash('success','Invalid Email & and password');
return redirect()->route('index');
}
}
and when I get the session id then it returns me null
public function studentview()
{
$id=session()->get('id');
dd($id);
//return view('student.studentview');
}
Actually I want the value of the row which row i used to login.
and pass the student view pages. please help me.
Change your code..You are assigning $request->id to session variable..Actual value needed is $students->id.
put use Session; at the top of your controller.
public function login(Request $request){
$email=$request->email;
$password=$request->password;
$students=Student::where('email','=',$email)
->where('password','=',$password)
->first();
if($students){
Session::put('email',$students->email);
Session::put('id',$students->id);
Session::save();
//dd($students);
return redirect()->route('student.dashboard');
}
else{
Session()->flash('success','Invalid Email & and password');
return redirect()->route('index');
}
}
public function studentview()
{
if(Session::has('id'))
{
$id=Session::get('id');
dd($id);
}
//return view('student.studentview');
}
I am trying to using middleware in laravel but it is giving this error
"The page isn’t redirecting properly"
i have done this
IsAdmin(middleware)
public function handle($request, Closure $next)
{
$user=Auth::user();
if($user->isAdmin())
{
return redirect()->intended('/admin');
}
return $next($request);
}
}
admin controller
class AdminController extends Controller
{
public function __construct()
{
$this->middleware('IsAdmin');
}
public function index()
{
return "You are an administrator because you are seeing this page";
}
}
User Model
public function isAdmin()
{
if($this->role->name=='administrator')
{
return true;
}
return false;
}
web.php
Route::get('/admin','AdminController#index');
"The page isn’t redirecting properly"
Try changing return $next($request); to return redirect()->back();, it might be infinite redirect loop, because you are still trying to access the same route even if middleware fails.
show error : Missing argument 1 for App\Http\Controllers\AdminLoginController::name()
public function name($username) {
$user = AdminLogin::find($username);
return response()->json($user);
}
AdminLoginController: Its a adminlogin controller code
class AdminLoginController extends Controller{
public function show(){
$res ="Hello world!";
return response()->json($res);
}
public function log() {
$users = AdminLogin::all();
return response()->json($users);
}
public function name($username) {
$user = AdminLogin::where('username',$username)->first();
return response()->json($user);
}
RouteLoginController: Its a adminlogin controller code :
<?php
$app->get('/', function () use ($app) {
return $app->version();
});
$app->group(['prefix' => 'api/v1'], function ($app)
{
$app->get('adminlogin', 'AdminLoginController#show'); //get single route
$app->get('user', 'AdminLoginController#log'); //get single route
$app->get('username', 'AdminLoginController#name'); //get single route
$app->post('adminlogin', 'AdminLoginController#login'); //get single route
});
Error :
(1/1) ErrorException
Missing argument 1 for App\Http\Controllers\AdminLoginController::name()
Your controller method is taking the username param but the route binding is not passing one. Change your route
$app->get('username', 'AdminLoginController#name');
to
$app->get('user/{username}', 'AdminLoginController#name');
If you don't want to change your route, change your controller function signature to the below (as shown in the other answers), and make sure you are passing the 'username' as request param while invoking the url.
public function name(\Illuminate\Http\Request $request) {
$user = AdminLogin::where('username',$request->username)->first();
return response()->json(['user' => $user]);
}
You are probably calling this function using an ajax request and putting the name in the query string. In this case, the name parameter will not be sent as an attribute of the function but will be part of the request object.
You can solve this like so:
public function name(\Illuminate\Http\Request $request) {
$user = AdminLogin::find($request->username);
return response()->json($user);
}
You should try this :
public function name($username) {
$user = AdminLogin::where('username',$username)->first();
return response()->json(['user' => $user]);
}
OR
public function name(\Illuminate\Http\Request $request) {
$user = AdminLogin::where('username',$request->username)->first();
return response()->json(['user' => $user]);
}