Where is Laravel Slack Webhook URL defined - php

Continuing with my Laravel 5.5 project, I'm confused as to where you define the slack webhook URL in the Laravel app.
https://laravel.com/docs/5.5/notifications#routing-slack-notifications shows defining a routeNotificationForSlack method on the User (or whatever notifiable model) that returns $this->slack_webhook_url-- but that var is never populated:
class User extends Authenticatable
{
use Notifiable;
public function routeNotificationForSlack()
{
return $this->slack_webhook_url;
}
Should the slack_webhook_url be hardcoded in this model, or is it passed in when you instantiate the notification?

it's up to you how to implement routeNotificationForSlack(), Laravel will only call it and use the return value to determine what url to ping.
If all your users share same webhook endpoint, you can store it in .env, if they are different for each user, return a database column like the example. If it depends on group/privilege, you should implement it accordingly

Related

where does laravel can function for user object define?

i am working on a laravel project .almost i see in each controller these line format :
!auth()->user()->can('something (differ from each controller to other one)')
but in my php editor it says method {can} not found for this object. so i try to found method can and not found it .even i edit __Call magic method to see if when can method is calling does magic function run but i know it never run for can function.so how it is possible to link function to object when it is not defined in class and its all mother class.and where does can function locate?i search and i see laravel has some policy for authorize users but yet i don not know how can function link to user object without
define in classes and even magic method does not run .and how can i develope these type of function (for authorizing in laravel and change policy)
can method is a part of Authorizable trait in Illuminate\Foundation\Auth\Access
Look at your User model, you will found that model is extended from Illuminate\Foundation\Auth\User as Authenticatable. and Authenticatable uses the above trait.
it's part of the core of laravel, you can read the documentation from official docs

Laravel change Reset Password email greeting with variable

I have an laravel 5.8 app, with the default auth installed. I want to pass a variable to the password reset email template, so the greeting would look like "Hello, [username]".
The current email template looks like this:
I didn't find where in the core files I can change this "Hello!" heading of the message
EDIT:
In my controller, I send the password reset like this(maybe the variable should be put somewhere on this line)
$response = Password::sendResetLink($credentials, function (Message $message) {
$message->subject($this->getEmailSubject());
});
In a default Laravel app, the User model has a CanResetPassword interface with a sendPasswordResetNotification method. This method is created in a CanResetPassword trait that the user also uses.
You could override this with your own method and create your own ResetPasswordNotification class. Try following it from the trait to that class.
It does not look like it uses a view for the markup, so it shouldn't be too hard to do. The ResetPassword class takes accepts a Notifiable, so you should have access to the name in there.

Laravel Passport API: Retrieve Authenticated Token

Situation
I'm using Laravel Passport API to communicate between Laravel and external "agents" via Personal Access Tokens: https://laravel.com/docs/5.5/passport#personal-access-tokens
You can create multiple tokens per user.
Authentication works and I can retrieve the User via Auth::User()
Question
How can I check which token is used?
Background
I want to use different tokens for different "agents" for the same user and I need to know which token is used to see who is connecting.
You can use:
Auth::user()->token()
function to get token model. This is object of class "Token extends Model" so you should be able to use it like any other model.
In addition in my project I also have that model:
namespace App;
use Illuminate\Database\Eloquent\Model;
class OauthAccessToken extends Model
{
//
}
and relation:
class User extends Authenticatable
{
//...
public function accessTokens()
{
return $this->hasMany('App\OauthAccessToken');
}
}
So I can simply access all tokens and for example delete them:
Auth::user()->accessTokens()->delete();

laravel 5.3 + Tymon\JWTAuth = How to create token with own authentication

Im building a Restful api, except that I DONT want to use Laravel's User authentication system (instead I use my own).
So im on stuck here:
$this->jwt_token = JWTAuth::attempt(['email'=>$email, 'pass'=>$pass])
which gives me the following error:
Type error: Argument 1 passed to
Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an
instance of Illuminate\Contracts\Auth\Authenticatable, instance of
App\User given, called in
**\vendor\laravel\framework\src\Illuminate\Auth\SessionGuard.php on line 387
So how do I solve this? any idea?
Thanks
It looks like your User model isn't extending the correct Eloquent class.
Pull up your user model, and make sure it extends Illuminate\Foundation\Auth\User.
In the default Laravel install, this is imported via use Illuminate\Foundation\Auth\User as Authenticatable, then the model extends Authenticatable.
If you don't want to use the User model for authenticating, you can change which model should be used in config/jwt.php, but whatever you choose will need to extend the Auth\User class as above.

Getting "ErrorException" while implementing Laravel 4 class Auth::login()

I'm building a web application where users can signup and post questions. Everything went alright until I was trying developing a function where users will be automatically logged in upon registration. I used Auth::login() class just like I used to do with Laravel 3 but I'm getting the following error:
"ErrorException Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Auth\UserInterface, instance of Member given"
while I implemented the class with registered user's creds. I guess Laravel 4 has changed the way the class would work in it's previous version but I can't figure it out in their documentation as well as searching here in StackExchange before I post this question.
Here is the codes in my UserController
public function postCreate() {
$validator = Member::validate(Input::all());
if ($validator->passes()) {
$user = Member::create(array(
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password'))
));
Auth::login($user);
return Redirect::route('home')->with('message', 'Thanks for registering!');
} else {
return Redirect::route('register')->withErrors($validator)->withInput();
}
}
I'm a bit confused about the default User.php model provided with Laravel 4. I usually would create a User model based on the users table in my database while I would work in laravel 3. But this time in laravel 4 I had to change my user table name to members so that I can use my own model Member.php. Is it alright if I remove the codes in default User model or should I place my own functions at the top keeping the existing codes provided by Laravel?
P.S. I'm relativeley new with the MVC concept and started learning with tutorials on Laravel 3 and that's why I'm finding it hard to get myself used to with Laravel 4.
You must implement UserInterface to fix the error. In addition, if you need password reminder functionality, you have to implement RemindableInterface as well.
In your Member class add the following lines:
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class Member extends Eloquent implements UserInterface, RemindableInterface {
As the Exception says, your Member-Model needs to implement UserInterface in order to use the Auth helper:
class Member extends Eloquent implements UserInterface
Here a quote from Code Bright by Dayle Rees:
Our User model implements both UserInterface and RemindableInterface. What are these for?
Well the UserInterface let’s Laravel know that the model contains all methods needed for it to
authenticate with Laravel’s own authentication system. The RemindableInterface allows Laravel
to retrieve the users email address or other contact information to allow for the functionality of
sending password reminder emails.

Categories