Skip to content

Commit

Permalink
feat(contact): Edit contact inside Prospect/Customer view #117 WITHOU…
Browse files Browse the repository at this point in the history
…T AJAX
  • Loading branch information
elguitarraverde committed Mar 22, 2023
1 parent 423c222 commit 4670556
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 81 deletions.
4 changes: 3 additions & 1 deletion app/Http/Controllers/Contact/ContactCreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
use App\Http\Controllers\Controller;
use App\Models\Contact;
use Illuminate\Http\Request;
use Illuminate\View\View;

class ContactCreateController extends Controller
{
public function create(Request $request)
public function create(Request $request, string $model, string $id_model): View
{
$contact = new Contact();
$contact->{$model.'_id'} = $id_model;

return view('contact.contact', compact('contact'));
}
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/Contact/ContactSaveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Http\Controllers\MainController;
use App\Repositories\ContactRepository;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class ContactSaveController extends MainController
Expand All @@ -17,10 +18,12 @@ public function __construct(ContactRepository $contactRepository)
$this->contactRepository = $contactRepository;
}

public function save(Request $request)
public function save(Request $request): RedirectResponse
{
$contact = $this->contactRepository->save($request->all());

return back();
$url = $contact->lead_id ? 'lead/show/'.$contact->lead_id : 'customer/show/'.$contact->customer_id;

return redirect($url);
}
}
155 changes: 79 additions & 76 deletions resources/views/contact/contact.blade.php
Original file line number Diff line number Diff line change
@@ -1,83 +1,86 @@
@php
$lead_id = (empty($lead_id) && !empty($contact->lead_id)) ? $contact->lead_id : null;
$customer_id = (empty($customer_id) && !empty($contact->customer_id)) ? $contact->customer_id : null;
@endphp
<form method="post" action="{{ url('/contact/save') }}">
@csrf
<input type="hidden" name="id" value="{{ !empty($contact) ? $contact->id : '' }}">
<input type="hidden" name="lead_id" value="{{ !empty($lead_id) ? $lead_id : '' }}">
<input type="hidden" name="customer_id" value="{{ !empty($customer_id) ? $customer_id : '' }}">
<div class="row">
<div class="col">
<label for="contact_first_name">{{ __('First name') }}</label>
<input type="text" name="contact_first_name" id="contact_first_name"
value="{{ !empty($contact) ? $contact->first_name : '' }}" required class="form-control">
</div>
<div class="col">
<label for="contact_last_name">{{ __('Last name') }}</label>
<input type="text" name="contact_last_name" id="contact_last_name"
value="{{ !empty($contact) ? $contact->last_name : '' }}" class="form-control">
</div>
</div>
<div class="row">
<div class="col">
<label for="contact_phone">{{ __('Phone') }}</label>
<div class="input-group">
<span class="input-group-text"><i class="las la-phone"></i></span>
<input type="tel" name="contact_phone" id="contact_phone"
value="{{ !empty($contact) ? $contact->phone : '' }}" maxlength="15" class="form-control">
@extends('layouts.app')

@section('content')
@include('layouts.partials._header', ['title' => __('Contact')])

<div class="card">
<div class="card-body">
<form method="post" action="{{ url('/contact/save') }}">
@csrf
<input type="hidden" name="id" value="{{ !empty($contact) ? $contact->id : '' }}">
<input type="hidden" name="lead_id" value="{{ !empty($contact) ? $contact->lead_id : '' }}">
<input type="hidden" name="customer_id" value="{{ !empty($contact) ? $contact->customer_id : '' }}">
<div class="row">
<div class="col">
<label for="contact_first_name">{{ __('First name') }}</label>
<input type="text" name="contact_first_name" id="contact_first_name" value="{{ !empty($contact) ? $contact->first_name : '' }}" required class="form-control">
</div>
<div class="col">
<label for="contact_last_name">{{ __('Last name') }}</label>
<input type="text" name="contact_last_name" id="contact_last_name" value="{{ !empty($contact) ? $contact->last_name : '' }}" class="form-control">
</div>
</div>
</div>
<div class="col">
<label for="contact_mobile">{{ __('Mobile') }}</label>
<div class="input-group">
<span class="input-group-text"><i class="las la-mobile"></i></span>
<input type="tel" name="contact_mobile" id="contact_mobile"
value="{{ !empty($contact) ? $contact->mobile : '' }}" maxlength="15" class="form-control">
<div class="row">
<div class="col">
<label for="contact_phone">{{ __('Phone') }}</label>
<div class="input-group">
<span class="input-group-text"><i class="las la-phone"></i></span>
<input type="tel" name="contact_phone" id="contact_phone" value="{{ !empty($contact) ? $contact->phone : '' }}" maxlength="15" class="form-control">
</div>
</div>
<div class="col">
<label for="contact_mobile">{{ __('Mobile') }}</label>
<div class="input-group">
<span class="input-group-text"><i class="las la-mobile"></i></span>
<input type="tel" name="contact_mobile" id="contact_mobile" value="{{ !empty($contact) ? $contact->mobile : '' }}" maxlength="15" class="form-control">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<label for="contact_email">E-mail</label>
<div class="input-group">
<span class="input-group-text"><i class="las la-envelope"></i></span>
<input type="email" name="contact_email" id="contact_email"
value="{{ !empty($contact) ? $contact->email : '' }}" maxlength="254" class="form-control">
<div class="row">
<div class="col">
<label for="contact_email">E-mail</label>
<div class="input-group">
<span class="input-group-text"><i class="las la-envelope"></i></span>
<input type="email" name="contact_email" id="contact_email" value="{{ !empty($contact) ? $contact->email : '' }}" maxlength="254" class="form-control">
</div>
</div>
<div class="col">
<label for="contact_linkedin">Linkedin</label>
<div class="input-group">
<span class="input-group-text"><i class="lab la-linkedin-in"></i></span>
<input type="url" name="contact_linkedin" id="contact_linkedin" placeholder="https://linkedin.com/in/" value="{{ !empty($contact) ? $contact->linkedin : '' }}" class="form-control">
</div>
</div>
</div>
</div>
<div class="col">
<label for="contact_linkedin">Linkedin</label>
<div class="input-group">
<span class="input-group-text"><i class="lab la-linkedin-in"></i></span>
<input type="url" name="contact_linkedin" id="contact_linkedin" placeholder="https://linkedin.com/in/"
value="{{ !empty($contact) ? $contact->linkedin : '' }}" class="form-control">
<div class="row">
<div class="col">
<label for="contact_job_title">{{ __('Job title') }}</label>
<div class="input-group">
<span class="input-group-text"><i class="las la-briefcase"></i></span>
<input type="text" name="contact_job_title" id="contact_job_title" value="{{ !empty($contact) ? $contact->job_title : '' }}" maxlength="80" class="form-control">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<label for="contact_job_title">{{ __('Job title') }}</label>
<div class="input-group">
<span class="input-group-text"><i class="las la-briefcase"></i></span>
<input type="text" name="contact_job_title" id="contact_job_title"
value="{{ !empty($contact) ? $contact->job_title : '' }}" maxlength="80" class="form-control">
<div class="row">
<div class="col">
<label for="contact_notes">{{ __('Notes') }}</label>
@php
$notes = !empty($contact) ? $contact->notes : '';
@endphp
<textarea name="contact_notes" id="contact_notes" class="form-control">{{ $notes }}</textarea>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<label for="contact_notes">{{ __('Notes') }}</label>
@php
$notes = !empty($contact) ? $contact->notes : '';
@endphp
<textarea name="contact_notes" id="contact_notes" class="form-control">{{ $notes }}</textarea>
</div>
</div>
<div class="row">
<div class="col mt-2">
<button type="submit" class="btn btn-secondary">{{ __('Save') }}</button>
</div>
<div class="row">
<div class="col mt-2">
<button type="submit" class="btn btn-secondary">{{ __('Save') }}</button>
@php
$url = $contact->lead_id ? 'lead/show/' . $contact->lead_id : 'customer/show/' . $contact->customer_id;
@endphp
<a href="{{ url($url) }}" class="btn btn-secondary">{{ __('Cancel') }}</a>
</div>
</div>
</form>
</div>
</form>
</div>

@endsection
2 changes: 1 addition & 1 deletion resources/views/lead_customer/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class="btn btn-sm btn-primary text-white">
<div class="row">
<div class="col">{{ __('Contacts') }}</div>
<div class="col">
<a class="btn btn-primary btn-sm" href="{{ url('/contact/create') }}">{{ __('New') }}</a>
<a class="btn btn-primary btn-sm" href="{{ url('/contact/create', [$url, $item->id]) }}">{{ __('New') }}</a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
// Contact
Route::post('/contact/save', [\App\Http\Controllers\Contact\ContactSaveController::class, 'save']);
Route::get('/contact/export-vcard/{id}', [\App\Http\Controllers\Contact\ContactExportVCard::class, 'export']);
Route::get('/contact/create', [\App\Http\Controllers\Contact\ContactCreateController::class, 'create']);
Route::get('/contact/create/{model}/{id_model}', [\App\Http\Controllers\Contact\ContactCreateController::class, 'create']);
Route::get('/contact/update/{id}', [\App\Http\Controllers\Contact\ContactUpdateController::class, 'update']);
Route::get('/contact/delete/{id}', [\App\Http\Controllers\Contact\ContactDeleteController::class, 'delete']);

Expand Down

0 comments on commit 4670556

Please sign in to comment.