I am trying to use vinkla/pusher on Laravel 5.1
This is what I've added to app.php:
Vinkla\Pusher\PusherServiceProvider::class as a service provider
'LaravelPusher' => Vinkla\Pusher\Facades\Pusher::class, as a facade.
Route:
Route::get('/api/bid', [
'uses' => 'APIController#bid'
]);
And this is the controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\CurrentAuction;
use App\User;
use App\Bid;
use Session;
use LaravelPusher;
class APIController extends Controller
{
public function getCurrentAuction()
{
// snip...
}
public function bid(User $user) {
// Whole heap of things done with $user...
// snip...
$data['bids'] = 1;
LaravelPusher::trigger('bid_channel', 'NewBid', $data);
}
}
Calling that method does everything except trigger the pusher event.
I don't understand what I've done wrong.
Any help would be greatly appreciated. Thanks!
It appears that when using Laravel Homestead/Vagrant, pusher, broadcasting or anything like that doesn't want to work for me.
I pushed everything up to a live server and it worked without any code changes.
Related
I'm developing an eccomerce site. and im getting this error on checkout. please help
here are the defined routes:
//payfast payment
Route::get('payment', 'PaymentController#confirmpayment')->name('confirmPayment');
Route::get('/payfast/success','PaymentController#success')->name('payment.success');
Route::get('/payfast/cancel','PaymentController#cancel')->name('payment.cancel');
and here is the Controller (destination route):
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use NunoMaduro\Collision\Provider;
use App\Models\Cart;
use App\Models\Product;
use DB;
use Billow\Contracts\PaymentProcessor;
Class PaymentController extends Controller
{
public function confirmpayment(PaymentProcessor $payfast)
{
$cart = Cart::where('user_id',auth()->user()->id)->where('order_id',null)->get()->toArray();
$data = [];
When you use Laravel Named Route name(), you have to use it.
Route::get('payment', 'PaymentController#confirmpayment')->name('confirmPayment');
Instead of using
payment
replace it with
confirmPayment
change your HTTP method from get to post
like this:
Route::post('payment', 'PaymentController#confirmpayment')->name('confirmPayment')
it seems you don't have route named payment you only have
confirmPayment
payment.success
payment.cancel
I'm using 2 routes, one for loginUsingId(1), and the second one for test if user is logged.
When try to see Auth::id(), it is ever null.
//My Routes
Route::get('/login', [\App\Http\Controllers\UserController::class,'login']);
Route::get('/test_login', [\App\Http\Controllers\UserController::class, 'getUser']);
This are the methods in UserController
namespace App\Http\Controllers;
use App\Http\Middleware\Authenticate;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
public function login()
{
$auth = Auth::loginUsingId(3);
return var_dump($auth); // <--- here return 3
}
public function getUser()
{
return response(['user'=>Auth::id()]);
}
you need to apply middleware to work Auth::user()
Route::get('/test_login', [\App\Http\Controllers\UserController::class, 'getUser'])->middleware('auth');
then try
If you don't want to use the default Auth middleware it's not gonna work.
Although, remember there is the
auth()->user()
method that you can try instead ; it's more convenient as you don't need to import any model to use it.
I have a problem with Laravel notifications. I try to give a user notification about something, but Laravel cannot find notification class.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
class NotificationController extends Controller
{
public function getNot(Request $request)
{
$user = Auth::user();
$user->notify(new NewPost('a'));
}
}
I've also created a notification with the name NewPost.php, the problem is:
Class 'App\Http\Controllers\NewPost' not found
this one, so in the User model already included Notifications and notifiable.
Add use statement before class definition.
use Illuminate\Http\Request;
use Auth;
use App\Notifications\NewPost;
I assume that you create notification by artisan, if no, then keep in mind that namespace could be different.
I'm trying to add notification system to my Laravel project. I' watched this video to understand the system : https://www.youtube.com/watch?v=iDDUxqpNgSc
Notification table, model et controller are created. Also, i have created the view with Vue.JS and Pusher. It's work well !
However, in the notification controller, when i try to user Auth::user() method it's return null. I read somewhere it's because the middleware 'auth' is not already load when the controller is.
This is my NotificationsController file :
<?php
namespace App\Http\Controllers;
use App\Notification;
use Illuminate\Http\Request;
use App\Idea;
use App\User;
use Illuminate\Support\Facades\Auth;
class NotificationsController extends Controller
{
public function __construct()
{
}
function get(){
$notification = Auth::user()->unreadNotifications()->get();
return $notification;
}
function read(Request $request){
Auth::user()->unreadNotifications()->find($request->id)->markAsRead();
}
}
Do you have any idea how to solve this ?
Thank's for your time !
The answer was not about the Auth::user (It's accessible). I just baldy defined the notifiable_type in my model. It was App\Idea, it should be App\User
I am using laravel 5.0
I am trying to route the following. But it is not working
Route::post('accesscontrols/permissions', 'AccescontrolsController#permission');
I don't know what error in this.
It does not access permissions function in AccesscontrolsController
I have a function in AccesscontrolsController
public function permission()
{
$roles = DB::table('roles')->get();
$permissions = DB::table('permissions')->get();
return view('accesscontrols.permission', compact('roles', 'permissions'));
}
What I have did wrong?
Your route declaration should be made in app/Http/routes.php.
Also, make sure that your controller is within the App\Http\Controllers namespace and that it extends App\Http\Controllers\Controller.
Ex:
<?php
namespace App\Http\Controllers;
use App\User;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
public function permission()
{
...
Also, if you whish to test it in the browser (by typing "accesscontrols/permissions" in the address bar), you route should answer to the GET verb. Try to declare it using Route::get( instead.
You are returning a view in your method and you are not working with any POST data, which is strange. Are you sure you want POST request and not GET?