Building a support ticket system with lucid and laravel part 3
What Will I Learn?
For this installment of the tutorial, we are going to learn the following
- How to create a route
- Creating a controller
- Create a feature
- Sending data to our view
Requirements
The requirements for this tutorial are:
- Download php 7.2.1
- Download Composer.exe
- Download xampp or wamp for windows.
Difficulty
- Intermediate
Welcome to our part 3 of building a ticket system. In our last series, we were taught how to register a service a we created our several models. we are going to be studying the following below.
1. What is a route and our first route creation.
The route is a specified link (url on the browser) that triggers a controller.
We would start by creating our first route in our web service we are going to creating a new_ticket
route. This route is responsible for deliver a ticket for for entry by the user.
Open the web.php file in the routes folder and paste the code below.
Route::get('new_ticket', 'TicketController@create');
This code is responsible for listening when the url was clicked and send the request to the controller.
Next up
creating our controller
Lets call this controller TicketController.php
Our controller is responsible for serving features, To create this controller, we head over to the lucid CLI (command line interface) which is located on the vendor/bin
of our project directory.
to generate the controller paste the code below on the command line in the above directory
lucid make:controller Ticket web
'web' at the ending of the codes show the name of the service
now lets open our generated TicketController
in the create funtion, add the code below.
return $this->serve(CreateTicketFeature::class);
and remember to use the TicketFeature.php at the top
use App\Services\Web\Features\CreateTicketFeature;
The code above includes the file CreateTicketFeature
Creating the feature
The feature is also generated lucid, enter the code below on the cli
lucid make:feature CreateTicket web
paste the code below
<?php
namespace App\Services\Web\Features;
use Lucid\Foundation\Feature;
use Illuminate\Http\Request;
use App\Domains\Categories\Jobs\ListAllCategoryJob;
use Illuminate\Support\Facades\Auth;
class CreateTicketFeature extends Feature
{
public function handle(Request $request)
{
$categories = $this->run(ListAllCategoryJob::class);
return view('tickets.create', compact('categories'));
}
}
Noticed we are sending a data to the ticket view.
@extends('layouts.app')
@section('title', 'Open Ticket')
@section('content')
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Open New Ticket</div>
<div class="panel-body">
@include('includes.flash')
<form class="form-horizontal" role="form" method="POST" action="{{ url('/new_ticket') }}">
{!! csrf_field() !!}
<div class="form-group{{ $errors->has('title') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Title</label>
<div class="col-md-6">
<input id="title" type="text" class="form-control" name="title" value="{{ old('title') }}">
@if ($errors->has('title'))
<span class="help-block">
<strong>{{ $errors->first('title') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('category') ? ' has-error' : '' }}">
<label for="category" class="col-md-4 control-label">Category</label>
<div class="col-md-6">
<select id="category" type="category" class="form-control" name="category">
<option value="">Select Category</option>
@foreach ($categories as $category)
<option value="{{ $category->id }}">{{ $category->name }}</option>
@endforeach
</select>
@if ($errors->has('category'))
<span class="help-block">
<strong>{{ $errors->first('category') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('priority') ? ' has-error' : '' }}">
<label for="priority" class="col-md-4 control-label">Priority</label>
<div class="col-md-6">
<select id="priority" type="" class="form-control" name="priority">
<option value="">Select Priority</option>
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>
@if ($errors->has('priority'))
<span class="help-block">
<strong>{{ $errors->first('priority') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('message') ? ' has-error' : '' }}">
<label for="message" class="col-md-4 control-label">Message</label>
<div class="col-md-6">
<textarea rows="10" id="message" class="form-control" name="message"></textarea>
@if ($errors->has('message'))
<span class="help-block">
<strong>{{ $errors->first('message') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-ticket"></i> Open Ticket
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
@endsection
final we have sent to the view on the next we would talk about jobs and specifically the ListAllCategoryjob we used in the feature see you next time. check out my previous tutorial on creating a support ticket.
Curriculum
download the repository here
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
Note
You can contact us on Discord.
[utopian-moderator]
Hey @sirfreeman I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x