namespace App\Http\Controllers;
use Auth;
use Illuminate\Http\Request;
class maincontroller extends Controller
{
public function home(Request $request)
{
if(Auth::Attempt($request->only('email','password'))) {
return redirect('/');
}
}
}
Change the Auth namespace to:
use Illuminate\Support\Facades\Auth;
You may use the auth helper instead and then no worries about any class name
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class maincontroller extends Controller
{
public function home(Request $request)
{
if(auth()->attempt($request->only('email','password'))) {
return redirect('/');
}
}
}
Try this :
\Auth::attempt([...]);
I think this is helpfull..
Use the Auth namespace to:
use Illuminate\Support\Facades\Auth;
Related
When i execute my code that returns:
Class 'app\Nota' not found
I try use app\Notas::all(); instead app\Nota::all();, in the controller, but didn't work. I try too use app\Notas; instead app\Nota; but didn't worked for me.
My model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Nota extends Model
{
//
}
My controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use app\Nota;
class productoController extends Controller
{
public function show($id){
$notas = app\Nota::all();
print_r($notas);
die;
}
}
What can be the problem?
Replace your controller code like -
<?php
namespace App\Http\Controllers;
use App\Nota;
use Illuminate\Http\Request;
class productoController extends Controller
{
public function show($id){
$notas = Nota::all();
dd($notas);
}
}
Try using the following:
$notas = Nota::all();
and replace use app\Nota; by use App\Nota;
When I try to call API then I got this error.
Here is My Controller
<?php
namespace App\Http\Controllers;
use App\Video;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class VideoController extends Controller
{
public function index(){
//return 'index function of video controller';
$Video = DB::table('videos')->get();
return responce()->json($Video);
}
}
?>
here is my web.php
$app->get('/', 'VideoController#index');
You should return $Video or any other variable or array, not a function response()
EDIT
try to just return json_encode($Video);
Hello i am trying to use a trait from controller in my register controller but it can't seem to find it
the error message:
Trait 'MailVerification' not found
The class in which i want to use the trait
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
use RegistersUsers;
use MailVerification;
Here i call the function
protected function create(array $data)
{
$mail = $data['email'];
$this->sendVerification($mail);
Here is the trait in the class i am trying to import it from
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Mail\TestMail;
use Illuminate\Support\Facades\Mail;
use App\Http\Controllers\Controller;
use Session;
trait MailVerification
{
public function sendVerification($mail)
{
$verification_code = str_random(30);
Mail::send('mail.verify', ['verification_code' => $verification_code, 'mail' => $mail], function ($message) use ($mail)
{
$message->from('test#laravel.com');
$message->to($mail);
});
Session::flash('message', "Please check you're email to verify your account");
return redirect('/');
}
}
class MailController extends Controller
{
I have the trait outside of my class i don't know if this is correct but it was giving me an error while it was inside the class.
The namespace of your controller RegisterController and your trait MailVerification is different...
So, you'll have to add this line to your RegisterController
use App\Http\Controllers\MailVerification;
Also, I suggest you to put all your traits inside App\Traits folder instead of your controller. Try following a simpler way if possible :)
Edit --
This is how you register controller should look like
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use App\Http\Controllers\MailVerification;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
use RegistersUsers, MailVerification;
//Your code here....
}
route in routes.php
Route::get('korisnici', array('uses'=>'MojPrviKontroler#prvaAkcija'));
//
my controler in Controllers
<?php
use App\User;
use App\Http\Controllers\Controller;
class MojPrviKontrolerController extends Controller
{
public $restful = true;
public function get_prvaAkcija()
{
return View::make('prviViewovi.PrviView.php');
}
}
Can somebody tell my why my controller isn't found?
Seems like a wrong namespace problem.
Change to this:
<?php
namespace App\Http\Controllers;
use App\User;
I make a middleware RedirectIfNotStudent
public function handle($request, Closure $next, $guard = 'student')
{
if (!Auth::guard($guard)->check()) {
return redirect('/student/login');
}
return $next($request);
}
I create a new directory As StudentAuth for Authentication and these methods are there
public function showLoginForm()
{
if (Auth::guard('student')->check())
{
return redirect('/student');
}
return view('student.login');
}
public function logout(){
Auth::guard('student')->logout();
return redirect('/student/login');
}
I add a new row in Kernel File
'user' => \App\Http\Middleware\RedirectIfNotUser::class,
My Route for this is here
Route::get('student','StudentAuth\StudentAuthController#showLoginForm');
Route::post('student','StudentAuth\StudentAuthController#login');
StudentAuthController
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
RedirectIfNotUser
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
Change your namespace :
namespace App\Http\Controllers\Auth;
With
namespace App\Http\Controllers\StudentAuth;
StudentController
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;