I have developed an API with lumen. The front end is developed using Angular. Now I need to provide some data to another party through an API. I am confused with the authentication part of this. Please help me solve this.
via Chebli Mohamed
I have developed an API with lumen. The front end is developed using Angular. Now I need to provide some data to another party through an API. I am confused with the authentication part of this. Please help me solve this.
Laravel documentation says that we can pass parameter to a middleware specifying with :. here
So, If I am passing a guard as a parameter to guest or auth middleware like :
$this->middleware('guest:admin')
OR
$this->middleware('auth:admin')
What does that mean?
As here in AdminController.php
class AdminController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/admin/dashboard';
public function __construct()
{
$this->middleware('auth:admin')->except(['show_login','login']);
$this->middleware('guest:admin')->only(['show_login','login']);
}
}
I have three table
hotel
hotel_feature
hotel_feature_assing
hotel and hotel_feature have many to many relation
In hotel_feature_assing I will save id of hotel and id of the feature.
In edit section I have check box, I want to show check box checked if current hotel(editing one) have the feature. How can I check that the current hotel is already assigned to make checked my checkbox?
this is my Hotel Model:
public function features()
{
return $this->belongsToMany(HotelFeature::class, 'hotel_feature_assigns');
}
and in HotelFeature model:
public function hotel()
{
return $this->belongsToMany(Hotel::class);
}
this is my checkbox:
@foreach($hotelfeatures as $key => $hotelfeature)
<input type="checkbox" name="idhotelfeature[]" id="idhotelfeature" value=""
style="margin-right:5px" @if ($hotel->is_feature)
checked
@endif><span class="font-weight-normal"></span>
@endforeach
The GET method is not supported for this route. Supported methods: POST. When I Click on <a href=""> tag. i want post data .
<form method="post" action="">
<input type="hidden" name="zipcode" value="90002">
<a href="">View Trial Details</a>
</form>
The GET method is not supported for this route. Supported methods: POST. When I Click on tag. i want post data .
I'm working with laravel 5.7 and vue.js, with shinobi package, I'm restricting the users access.
When I try to hide button (new button), to create categories which one is in Categoria.vue component, but doesn't recognize the helper @can
Code for web.php: My route
I hope you can help me
Code for web.php: My route
Route::middleware(['auth'])->group(function(){
//CATEGORIAS
route::post('/categoria/registrar', 'CategoryController@store')->name('categoria.registrar')
->middleware('permission:categoria.registrar');
.........
}
Code of Categoria.vue component
Div (here is the button):
<div class="card-header">
<i class="fa fa-align-justify"></i> Categorías
@can('categoria.registrar')
<button type="button" @click="abrirModal('categoria', 'registrar')" class="btn btn-secondary">
<i class="icon-plus"></i> Nuevo
</button>
@endcan
</div>
como puedo guardar de dos tablas lo que selecciono en una tabla pivote
eso guarda, pero yo quiero que solo guarde en la pivote y no de nuevo la respuesta.
I'm having trouble rendering my Mailable on a view. I can clearly see (in telescope) that the my post request has a session with the array key "preview" but nothing shows up.
When debugging the value of my response, I find that my view-data has it's preview key set to the correct stringified render of the view between 2 more quotes ("")
For Example:
[
"preview": """<html></html>"""
]
Here is my code:
View: Where I check whether the $preview has been defined in the $res variable from the controller.
</div>
@isset($preview)
<hr>
<div class="form-group row">
<div class="col">
<h4>Preview:</h4>
<div class="form__preview">
</div>
</div>
</div>
@endisset
</form>
Controller: In my Action I execute my sendMail Action
public function mail(PotentialClientRequest $request)
{
$sendMail = new PotentialClientAction();
$res = $sendMail->execute($request);
return back()->with($res);
}
Action: Here we return the View or send a Mail (and return a success message).
<?php
namespace App\Http\Actions;
use App\Mail\PotentialClientMail;
use Illuminate\Support\Facades\Mail;
use Illuminate\Foundation\Http\FormRequest;
class PotentialClientAction
{
public function execute(FormRequest $request): array
{
$contact = $this->getData($request);
$mail = new PotentialClientMail($contact);
$response = [];
switch ($request->input('action')) {
case 'mail':
$response = $this->mail($mail);
break;
case 'preview':
$response = $this->preview($mail);
break;
default:
break;
}
return $response;
}
private function mail(PotentialClientMail $mail): array
{
Mail::to(env('MAIL_FROM_ADDRESS'))->queue($mail);
return [
'success' => 'Mail successfully sent!'
];
}
private function preview(PotentialClientMail $mail): array
{
return [
'preview' => $mail->render()
];
}
private function getData(FormRequest $request): array
{
$data = $request->validated();
$contact = [
'email' => $data['email'] ?? '-',
'email_cc' => $data['email_cc'] ?? '-',
'subject' => $data['subject'] ?? '-',
'body' => $data['body'] ?? '-'
];
return $contact;
}
}
Mailable:
public function build()
{
return $this
->subject($this->data['subject'])
->markdown('backend.mails.client')
->with([
'email' => $this->data['email'],
'email_cc' => $this->data['email_cc'],
'subject' => $this->data['subject'],
'body' => $this->data['body']
]);
}
Mail view:
@component('mail::message')
<p>Hi Foo,</p>
@component('mail::panel')
<p>
<strong>My email is:</strong> <a href="mailto:"></a><br>
<strong>My email_cc is:</strong> <a href="mailto:"></a><br>
<strong>My subject is:</strong> <br>
<strong>It's about:</strong>
</p>
<p></p>
@endcomponent
@component('mail::button', ['url' => 'mailto:' . $email])
Reply
@endcomponent
Company name,<br>
@endcomponent