-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bcfc75
commit 2c95a01
Showing
17 changed files
with
623 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Comment extends Model | ||
{ | ||
protected $guarded = ['id']; | ||
|
||
public function ticket() | ||
{ | ||
return $this->belongsTo('App\Ticket'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Requests\CommentFormRequest; | ||
use App\Comment; | ||
|
||
class CommentsController extends Controller | ||
{ | ||
public function newComment(CommentFormRequest $request) | ||
{ | ||
$comment = new Comment(array( | ||
'post_id' => $request->get('post_id'), | ||
'content' => $request->get('content') | ||
)); | ||
|
||
$comment->save(); | ||
|
||
return redirect()->back()->with('status', 'Your comment has been created!'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,6 @@ public function about() | |
|
||
public function contact() | ||
{ | ||
return view('contact'); | ||
return view('tickets.create'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Requests\TicketFormRequest; | ||
use App\Ticket; | ||
use Illuminate\Support\Facades\Mail; | ||
|
||
class TicketsController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
$tickets = Ticket::all(); | ||
return view('tickets.index', compact('tickets')); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function create() | ||
{ | ||
return view('tickets.create'); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(TicketFormRequest $request) | ||
{ | ||
$slug = uniqid(); | ||
$ticket = new Ticket(array( | ||
'title' => $request->get('title'), | ||
'content' => $request->get('content'), | ||
'slug' => $slug | ||
)); | ||
|
||
$ticket->save(); | ||
|
||
$data = array( | ||
'ticket' => $slug, | ||
); | ||
|
||
// Mail::send('emails.ticket', $data, function ($message) { | ||
// $message->from('[email protected]', 'Learning Laravel'); | ||
// | ||
// $message->to('[email protected]')->subject('There is a new ticket!'); | ||
// }); | ||
|
||
return redirect('/contact')->with('status', 'Your ticket has been created! Its unique id is: '.$slug); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show($slug) | ||
{ | ||
$ticket = Ticket::whereSlug($slug)->firstOrFail(); | ||
$comments = $ticket->comments()->get(); | ||
return view('tickets.show', compact('ticket', 'comments')); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit($slug) | ||
{ | ||
$ticket = Ticket::whereSlug($slug)->firstOrFail(); | ||
return view('tickets.edit', compact('ticket')); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update($slug, TicketFormRequest $request) | ||
{ | ||
$ticket = Ticket::whereSlug($slug)->firstOrFail(); | ||
$ticket->title = $request->get('title'); | ||
$ticket->content = $request->get('content'); | ||
if($request->get('status') != null) { | ||
$ticket->status = 0; | ||
} else { | ||
$ticket->status = 1; | ||
} | ||
$ticket->save(); | ||
return redirect(action('TicketsController@edit', $ticket->slug))->with('status', 'The ticket '.$slug.' has been updated!'); | ||
|
||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy($slug) | ||
{ | ||
$ticket = Ticket::whereSlug($slug)->firstOrFail(); | ||
$ticket->delete(); | ||
return redirect('/tickets')->with('status', 'The ticket '.$slug.' has been deleted!'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class CommentFormRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'content'=> 'required|min:3', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class TicketFormRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'title' => 'required|min:3', | ||
'content'=> 'required|min:10', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Ticket extends Model | ||
{ | ||
protected $fillable = ['title', 'content', 'slug', 'status', 'user_id']; | ||
|
||
public function comments() | ||
{ | ||
return $this->hasMany('App\Comment', 'post_id'); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
database/migrations/2018_10_01_180148_create_tickets_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateTicketsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('tickets', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('title', 255); | ||
$table->text('content'); | ||
$table->string('slug')->nullable(); | ||
$table->tinyInteger('status')->default(1); | ||
$table->integer('user_id')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('tickets'); | ||
} | ||
} |
Oops, something went wrong.