Reputation: 127
I have a view to create new customer and update customer. But I want to display 1 of 2 buttons when required. For example, when I want to create a new customer, the button is create, and when I want to update, the button is update. I'm a newbie, so can you specify what to do to help me? Thanks a lot !!
when i click to this link update below, it will return this view with button is update
<a href="{{url('customer/'.$customer->id)}}" name="update" > Update </a>
Below is function of route CustomersController after click to link above
class CustomersController extends Controller
{
function editCus($id)
{
$chanels = Group::childs('khachhang');
$customer = Customers::find($id);
$cities = City::where('country','VN')->get();
return view('sale.customer', compact('chanels','customer','cities'));
}
}
View sale.customer
<form class="form form-horizontal"
action=""
method="post">
<input type="hidden" name="_token" value="{{csrf_token()}}" >
<input type="hidden" name="contact_id" value="{{$contact->id}}" >
<input type="hidden" name="customer_id" value="{{$customer->id}}" >
@include('form.customer')
<div class="form-actions right">
<button class="btn btn-primary" type="submit" name="next" formaction="{{url('p/contact/customer')}}">
Create
</button>
<button class="btn btn-primary" type="submit" name="next" value="update"formaction="{{url('p/customer/update')}}">
Update
</button>
</div>
</form>
Upvotes: 0
Views: 57
Reputation: 185
You can simply add if...else condition like this.
@if(isset($customer->id) && $customer->id != null)
<button class="btn btn-primary" type="submit" name="next" value="update"formaction="{{url('p/customer/update')}}">
Update
</button>
@else
<button class="btn btn-primary" type="submit" name="next" formaction="{{url('p/contact/customer')}}">
Create
</button>
@endif
Upvotes: 1