I am going to integrate sabre soap api with laravel, the first step is to generate token can somebody please suggest, what strategy to be used to call sabre api for token.
via Chebli Mohamed
I am going to integrate sabre soap api with laravel, the first step is to generate token can somebody please suggest, what strategy to be used to call sabre api for token.
I have been using Laravel for almost a year now, but I am very new to creating my own packages and using Contracts, Repositories, Facades, etc..., so please bear with me.
I have having issues understanding if I am registering a facade correctly in my service provider. Here is the context (assume namespaces and imports have been correctly done. I am not including them so that this does not get too convoluted):
I want to create a facade called AdminServices to access a class called AdminServices:
class AdminServices implements AdminServicesContract
{
private $check;
public function __construct(CheckAdminContract $check)
{
$this->check = $check;
}
public function check()
{
return $this->check;
}
}
You'll notice that this class requires a contract, CheckAdminContract. This contract is implemented in the CheckAdmin class. Notice that this class requires a UserRepository:
class CheckAdmin implements CheckAdminContract
{
private $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function userIsAdmin(User $user)
{
return $user->roles()->whereAdmin()->count() > 0;
}
public function userIsAdminById($user_id)
{
$user = $this->userRepository->getById($user_id);
return $this->userIsAdmin($user);
}
public function userIsSuperAdmin(User $user)
{
return $user->roles()->whereSuperAdmin()->count() > 0;
}
public function userIsSuperAdminById($user_id)
{
$user = $this->userRepository->getById($user_id);
return $this->userIsSuperAdmin($user);
}
}
Here is the UserRepository:
interface UserRepository
{
public function getById($user_id);
}
Here is the EloquentUserRepository that implements the UserRepository:
class EloquentUserRepository implements UserRepository
{
private $model;
public function __construct()
{
$this->model = new User;
}
public function getById($user_id)
{
return $this->model->findOrFail($user_id);
}
}
Here is the Facade I want to register:
use Illuminate\Support\Facades\Facade;
class AdminServices extends Facade
{
protected static function getFacadeAccessor()
{
return 'admin-services';
}
}
Here is what I have registered in my Service Provider (all of the classes are properly imported via use directives):
public function register()
{
$this->app->singleton(UserRepository::class, EloquentUserRepository::class);
$this->app->singleton(CheckAdminContract::class, CheckAdmin::class);
$this->app->singleton(AdminServicesContract::class, AdminServices::class);
$this->app->singleton('admin-services', function(){
$userRepository = new EloquentUserRepository();
$checkAdmin = new CheckAdmin($userRepository);
return new AdminServices($checkAdmin);
});
}
So here is my big question:
Do I really have to explicitly instantiate all the repository and contract implementations when registering the facade accessor? I have already registered them as singletons above, so in my naive mind, I believe that instantiating these things again would be doing the work all over again, and if I decided to use a different implementation of these contracts and repositories, then I would have to change them more than once, which again in my naive mind seems like I am doing something wrong.
Can you please let me know if I am indeed doing this correctly in singleton for the facade accessor? Can you suggest a way that you have done something similar or a better way to do it?
Also, if you see that I am not doing something correctly or that my code is not very well written, please let me know how I can improve. Again, I am very new to these topics but I feel that I have a good enough understanding of them to do them somewhat properly. But I really would like some feedback so that I don't keep doing these things wrong (if I am doing them wrong).
Also, if there is a better way for me to structure or ask this question, again please let me know so that I don't make the same mistake more than once.
Thank you in advance for your help!
I am using laravel 5.4. And using oauth2 passport package.
i got a access token and refresh token in post man.
{
"token_type": "Bearer",
"expires_in": 31536000,
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImE1YTNiODUxZGNlMWQ4MTIxYzI2OWQyMzg1NzU0MzNmYWVkMzU5NmYwZWFmM2VhY2M0ODJmYzQ0YzIzODM1YTY5ODFmZDNhNWQxOGI2NWQ1In0.eyJhdWQiOiIyIiwianRpIjoiYTVhM2I4NTFkY2UxZDgxMjFjMjY5ZDIzODU3NTQzM2ZhZWQzNTk2ZjBlYWYzZWFjYzQ4MmZjNDRjMjM4MzVhNjk4MWZkM2E1ZDE4YjY1ZDUiLCJpYXQiOjE0OTM3MDA4OTMsIm5iZiI6MTQ5MzcwMDg5MywiZXhwIjoxNTI1MjM2ODkzLCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.KJwgqV0aibhiVXUAooCoUcGv17EqayLQFSPR2w5yjxzE4foCpyUDiBmQQ26-UK0CYZxZmjhK14tQhbDLz8GnWHrRja1Wzg13-xuobpFc4kZQ3rmCqP7cP3nRiO7N81zt6YDLV6piQNLhWF68LeIZj3IZ-ezWZY8_D2z_P-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fG5aMgV2obJcIb6OXjH6UFxMh21Pw86RG2Gst+RaVIoG2okrwUhqkhvJGIjKtoiqmDcbC7ksNm2SsnDsFR83mRXf9Tl/Ca/WRoi4THocNoikKEX4I51Y1frGa/bNDxiOAPdsQAEZOw="
}
Now i want to access user or some other routes from my laravel controller using this bearer access token in postman.
at the same time if anyone access data without using this token, i want show error of 401 (Unauthorized) in json.
Pls Answer Any one know the solution for this question.
I have an error on
php artisan dusk
error on cosole said
Failed to load resouces: net::ERR_FILE_NOT_FOUND
Manually run the test on browser the no such error found. The routes is correct and tested. The js is working.
I use http://ift.tt/PEjYy2 for form submission.
google-chrome version 58.0.3029
php 7.0.15-1ubuntu4
ubuntu 17.04
apache2 2.4.25
I have an admin-controller and i want to passe to it middle-ware to parameters to allow Super Admin to do admin stuff.
Here my controller:
class adminController extends Controller
{
public function __construct(){
$this->middleware('admin');
}
public function showGenerateCode(){
$code ="";
return view('create_code',compact('code'));
}
public function generateCode(Request $request){
$phone = $request['phone'];
$code = "";
$user = User::where('phone' ,'=',$phone)->first();
if($user){
$code = "Ce numero de telephone et deja associé a un utilisateur";
return view('create_code',compact('code'));
//dd($code);
}
else{
$code = "Code d'autorisation générer avec succé : ".substr($phone,1,3).rand(1000000,9999999);
return view('create_code',compact('code'));
}
}
}
I have tried multiple troubleshooting steps on this site about this error. Already added a $fillable and updated my composer but I am still getting the same error here is a screen shot of the error that I am experiencing and the codes for my Model.php
I'm doing a page where i can display a list of data with checkboxes. then i will automatically check with database and if the data is there, the checkbox will be checked. What i want to do now is, lets say the checkbox is checked automatically, andwhen i unchecked it myself and save, it will update the data in database.
Example of my coding:
<form action="" method="get">
<input name="_token" type="hidden" value=""/>
@foreach($var as $v)
<table style="margin-left:20px;">
<caption></caption>
@foreach($name as $n)
<?php if($n->module_groupname == $v->module_groupname){?>
<tr><td width="80"><input type="checkbox" name="module_code[]" value=""
<?php foreach($priv as $p){
if($p->user_id == $d->id){
if($p->module_code == $n->module_code){
echo 'checked="checked"';
}
}
}?>></td>
<td width="150"></td>
<td width="200"></td>
</tr> <?php } ?>
@endforeach
</table>
<hr>
@endforeach
<input type="submit" value="select" class="btn btn-s btn-success">
</form>
i've been advised to lookup for PLUS statement oracle but i couldnt find how