How could I initialize DataTable from Vue? - laravel

DataTable() removes the #click="editUser(user)" whenever I disable the initializing I get it working. But, once the table is rendered I cannot add the #click event. I also tried v-on:click
<button type="button" class="btn btn-warning btn-icon" #click="onClick(user)"><i class="la la-edit"></i></button>

Related

Submit Button not getting correct route to add new data in Laravel

I am facing problem for Submit Button not getting correct route to add new data.
2 Blade file with 2 Submit Button which need to save 2 data to 2 different tables.
Problem facing - Data submitted in 1 table for both submit button....
addnewBuffalo.blade.php
<div class="box-header with-border" align="right">
<button type="submit" class="btn btn-success btn"><i class="fa fa-floppy-o"></i> <b>Add
Buffalo</b></button><a href="" class="btn btn-warning btn"><i class="fa fa-refresh">
</i> <b> Refresh</b></a>
</div>
addnewcow.blade.php
<div class="box-header with-border" align="right">
<button type="submit" class="btn btn-success btn"><i class="fa fa-floppy-o"></i> <b>Add
Cow</b></button><a href="" class="btn btn-warning btn"><i class="fa fa-refresh"></i> <b>
Refresh</b></a>
</div>
web.php
Route:: post('submit', 'App\Http\Controllers\addnewbuffaloController#addbuffaloData')
->name('submit');
Route:: post('submit', 'App\Http\Controllers\addnewcowController#addcowData')
->name('submit');
You need to create 2 separate Route Names. Having ->name('submit') for both won't work. And having the same path won't work
Route::post('submit=buffalo', 'App\Http\Controllers\addnewbuffaloController#addbuffaloData')
->name('submit-buffalo');
Route::post('submit-cow', 'App\Http\Controllers\addnewcowController#addcowData')
->name('submit-cow');
Or if the form is wrapped by one form tag then you can handle both submissions in the one Controller action
<button type="submit" name="buffalo-submission">Save Buffalo</button>
<button type="submit" name="cow-submission">Save Cow</button>
Then in the controller action code you could check
if ($request->has('buffalo-submission') {
Do buffalo code
} else if ($request->has('cow-submission')) {
do cow code
}

Laravel 5.4 CRUD DELETE Method not working, there is no reaction on clicking DELETE

After clicking on DELETE, there is no reaction, absolutely nothing happens. I am using HTML Forms, that's why I used, #method('DELETE'). I had similar problem with edit, after using #method(PUT), edit is working properly.
<div class="row">
<div class="col-6 align-self-start">
<a class="btn btn-light" href="/listings/{{$listing->id}}/edit">Edit</a>
</div>
<div class="col-6 align-self-end">
<form action="{{action('ListingsController#destroy', [$listing->id])}}" method="POST">
<?= csrf_field()?>
#method('DELETE')
<a class="btn btn-danger" href="/dashboard">Delete</a>
</form>
</div>
</div>
Destroy Function:
public function destroy($id)
{
$listing = Listing::find($id);
$listing->delete();
return redirect('/dashboard')->with('success', 'Contact Deleted');
}
Change
<a class="btn btn-danger" href="/dashboard">Delete</a>
to
<a type="submit" class="btn btn-danger" href="/dashboard">Delete</a>
You should add submit otherwise it will not submit the form.
Its recommended to use a instead of :
<button type="submit" class="btn btn-danger">Delete</button>

Advice/guidance on how to turn this add tenant method into a request that can be accepted/rejected

I'm building a sample app in Laravel based around tenancies. Landlords can add tenants, but it's not an accept/request system. Once the Landlord clicks add and fills out a form, the tenancy is created.
This is a sample row in the database.
Database row.
I added the accepted method so a tenant can accept/reject, but it's just sitting there atm, it's not doing anything (yet). How can I allow the 'add' to be a request, and for the landlord to accept or reject it?
This is the profile page. I was thinking of having the logic like this. How hard is it?
<div class="container">
#if($user->userType != "Landlord")
<div class="row">
`//Add Tenancy - I'll start this so only lanlors can see this button`
`Start Tenancy`
`//If Tenancy request sent`
`button to accept or reject.`
`//If if in tenacny`
`list property address, or landlord name`
</div>
You can create a form around your Add Tenancy button and when the button is clicked the form is submitted and you're redirected where you want to go. This is how the default Laravel Auth example works when logging out.
<form method="POST" action="/account/tenancy/{{$user->id}}/create">
<button type="submit">Add Tenancy</button>
</form>
You can handle the request via routers/controller.
Edit
If you want to control the button based on the status of the tenancy you can pass a $status variable to your blade template and use it.
#if ( $status == 'can-add' )
<button type="submit" class="btn btn-primary">Add Tenancy</button>
#elseif ( $status == 'accepted' )
<button type="submit" class="btn btn-success" disabled>Accepted</button>
#elseif ( $status == 'denied' )
<button type="submit" class="btn btn-danger" disabled>Denied</button>
#elseif ( $status == 'pending' )
<button type="submit" class="btn btn-warning" disabled>Pending</button>
#else
<button type="submit" class="btn btn-default" disabled>A Default</button>
#endif

Laravel Form Button Cancel

Using Laravel, I have a form and I want to include a "cancel" button that just redirects back to a different route. Since the button is within the form element, when clicked it attempts to submit the form. In the Laravel docs I don't see a good way to do this. Any suggestions or would using Javascript be best?
Thanks,
<div class="form-group pull-right">
<button class="btn btn-default btn-close">Cancel</button>
<button type="submit" class="btn btn-global">Register</button>
</div>
Though it's a very late answer, But it might help others.
You can just redirect back where you have come from. Simply use the following code.
Cancel
It will send you back where you have came.
<a> elements in bootstrap can have the btn class and they will look just like a button, so you can take the button out and just have cancel be a link:
<div class="form-group pull-right">
<a class="btn btn-default btn-close" href="{{ route('home') }}">Cancel</a>
<button type="submit" class="btn btn-global">Register</button>
</div>
it does not have to do with laravel. You can simple use formaction attribute
<input type=submit formaction="anotherpage">
<button class="btn btn-default btn-close" formaction="{{ route('home') }}">Cancel</button>

font-awesome to be inserted in value="<spring:message text="View List"/>">

im trying to insert some font-awesome inside here
<form action="/someweb.html">
<input type="submit" class="btn btn-success" value="<spring:message text="View List"/>">
</form>
but it seems that this code
<i class="fa fa-list-ul fa-lg"></i>
wont fit inside, and i tried to insert it inside in different position, i always get failed result. all i wanted is to have this kind of look here.
hope you could help. thanks in advance.
I have not tried it completely, but this should give you an idea.
<form action="/someweb.html">
<button type="submit" class="btn btn-success"><i class='fa fa-list-ul fa-lg'></i><spring:message text="View List"/></button>
</form>
Here is a sample in codepen.
http://codepen.io/anon/pen/yNXvZw

Resources