Laravel FatalErrorException - laravel

I created a new view, route and controller in laravel and when i go to access the view i get an error, all other views are fine.
Error
FatalErrorException in shopsalescontroller.php line 11: syntax error, unexpected 'class' (T_CLASS), expecting ',' or ';'
this is my shop sales controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\shopsales
class shopsalescontroller extends Controller : (line 11)
{
public function index()
{
$storeNum = request('storeNum');
$results = shopsales::where('StoreNumber','=',$storeNum)->get();
return view('shopSales',compact('results'));
}
}
PHP version 5.6.3
Zend engine v2.6.0
Laravel framework version 5.2.45

You missed a semicolon on this line:
use App\shopsales;

Just remove the : (line 11) text from your code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\shopsales
class shopsalescontroller extends Controller {
public function index() {
$storeNum = request('storeNum');
$results = shopsales::where('StoreNumber', '=', $storeNum)->get();
return view('shopSales', compact('results'));
}
}

Related

How to use namespace in Laravel in controller?

I have a custom class in App/Helpers/regexValidation.php:
<?
namespace App\Helpers;
class RegexValidation
{
public static function isCVC($str)
{
$re = '/^[0-9]{3,4}$/s';
preg_match($re, $str, $matches);
return $matches;
}
}
I try to use it in controller:
<?php
namespace App\Http\Controllers;
use App\Helpers\RegexValidation;
public function detectfile(Request $request)
{
$cvc = RegexValidation::isCVC(555);
}
When I call this method from route Laravel I get:
Error: read ECONNRESET
If comment this line $cvc = RegexValidation::isCVC(555); it works.
What do I do wrong?
I think you are having a PSR4 Error,
I have a custom class in App/Helpers/regexValidation.php
Rename that file to PascalCase as RegexValidation.php
after renaming run
composer dumpautoload
And it should work.

Target class [FrontendController] does not exist

please help. I got this error "Target class [FrontendController] does not exist."
This is my route :
<?php
use Illuminate\Support\Facades\Route;
Route::get('/','FrontendController#home');
My Controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class FrontendController extends Controller
{
public function home()
{
return view ('index');
}
}
Why this happend? can anyone help me please? :(
You have to refer to the controller, you have 2 options
Laravel 7 and lower
Route::get('/','App\Http\Controllers\FrontendController#home');
If you are using Laravel 8 then you have to change the structure of the route
Route::get('/', [App\Http\Controllers\FrontendController::class, 'home']);

Laravel 5.7 SendEmail is not working properly

I am sending email using laravel 5.7 but i found following error " (1/1) FatalErrorException
Class 'App\Mail\UserRequest' not found" Need help
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
//use \App\Mail\SendMail;
use App\Mail\UserRequest;
class ContactusController extends Controller
{
public function index()
{
return view('contactus');
}
public function sendmail(Request $req)
{
$msgdata = array('subject'=>$req->subject,'email'=>$req->email,
'name'=>$req->name,'body'=>$req->message);
Mail::to('dddddddd#dddsdsf.com')->send(new UserRequest($msgdata));
return view('contactus');
}
}

Getting this error continuously: MethodNotAllowedHttpException in RouteCollection.php line 218:

When I tried to log in, on my website. It responded with the message:
FatalErrorException in UserController.php line 37:
Class 'App\Http\Controllers\Auth' not found
But, the file there is controllers folder in Http containing Auth where there are four files.
UserController:
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
//use Illuminate\Support\Facades\Flash;
use InvalidConfirmationCodeException;
use Flash;
//use Mail;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class UserController extends Controller
{
public function getDashboard()
{
return view('dashboard');
}
public function postSignUp(Request $request)
{
$email = $request['email'];
$name = $request['name'];
$password = bcrypt($request['password']);
$user = new User();
$user -> email = $email;
$user -> name = $name;
$user -> password = $password;
Auth::login('$user');
$user->save();
return redirect()->route('dashboard')
}
public function postSignIn(Request $request)
{
if (Auth::attempt(['email' => $request['email'], 'password' => $request['password']])) {
return redirect()->route('dashboard');
}
return redirect()->back();
}
}
also, I am getting an error while signup:
MethodNotAllowedHttpException in RouteCollection.php line 218:
And I am trying to solve this error from a very long time but no success till now.
Please help me with both the errors.
change Auth::login($user) --> \Auth::login($user)
and let me know if you are getting anything in database after signup . :)
To get rid off
FatalErrorException in UserController.php line 37: Class
'App\Http\Controllers\Auth' not found
Add use Auth at the top
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use Auth;
Change Auth::login($User) to \Auth::login($user), your $user variable is incorrect as well.
Check your signup route, is it doing a POST (most likely it is) and you're sending a GET request?
You need add
use Auth;
to your Controller.
I highly doubt that the Auth class is inside your Controllers directory. The Auth you are looking for, is probably the Auth facade, can be included this way:
use Illuminate\Support\Facades\Auth;

Laravel 5 pagination on raw query

I have a union query from 2 different tables which I have to run through raw query. But I am facing a problem in paginatig the result. Here's what I have done
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Pagination\Paginator;
use Illuminate\Http\Request;
class SiteController extends Controller {
public function index()
{
$result = \DB::select(\DB::raw("UNION query"));
$result_p = Paginator::make($result , count($result), 10);
return view('view_name',compact('result'));
}
}
This gives an error
Call to undefined method Illuminate\Pagination\Paginator::make()
Any help is appreciated.
That class does not contain the method make(). Instead, pass those variables to the constructor.
$result_p = new Paginator($result, $resultsPerPage, $currentPage, $options);

Resources