Skip to content

Instantly share code, notes, and snippets.

@connor11528
Last active January 20, 2019 21:22
Show Gist options
  • Save connor11528/e69385e5b5986b3d087db1cb3b35a9ac to your computer and use it in GitHub Desktop.
Save connor11528/e69385e5b5986b3d087db1cb3b35a9ac to your computer and use it in GitHub Desktop.
Laravel backend for adding tags to the Employbl candidate application
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Spatie\Tags\Tag;
class CandidateController extends Controller
{
public function edit($id)
{
$candidate = auth()->user();
if ($candidate->id != $id) {
abort(403, 'Forbidden');
}
// Get all the available tags candidates can select
$allTags = Tag::getWithType('candidate')->map(function ($tag) {
return $tag->only(['name']);
})->pluck('name');
$candidate->load([
'tags'
]);
// Only grab the name of the tags the candidate has (not the whole tag object)
$candidateTags = $candidate->tags->map(function($tag) {
return $tag->name;
});
return view('candidates.edit', compact('candidate', 'allTags', 'candidateTags'));
}
public function update(Request $request, $id)
{
$candidate = auth()->user();
if ($candidate->id != $id) {
abort(403, 'Forbidden. You can only update your own profile.');
}
$request->validate(
[
'summary' => 'nullable|string',
]
);
$user = User::find($id);
$user->summary = trim($request->input('summary'));
$tags = $request->input('tags');
$user->attachTags($tags);
$user->save();
return response()->json(
[
'message' => '🎉 You updated your profile!',
'candidate' => $user,
]
);
}
}
<?php
use Illuminate\Database\Seeder;
use Spatie\Tags\Tag;
class CandidateTagsSeeder extends Seeder
{
public function run()
{
// Storing possible tags in a Google docs
// Use formula: =ArrayFormula(""""&Sheet1!A:D&"""") for adding quotes
// https://delim.co/ can add commas
$allTags = ["Javascript","PHP","Ruby","Ruby On Rails","AWS","Node.js","MongoDB","Laravel","Python","Django","React.js","Vue.js","jQuery","Marketing","Content Marketing","Product Marketing","Product Management","Project Management","Customer Success","Sales","Recruiting","Human Resources","UX Design","UI Design","Design","Software Engineering","Java","MySQL","Customer Support","SQL","Google Cloud","DevOps","Chef","Puppet","Leadership","New Grad","MBA Grad","ES6","Director Level","C level","Bootcamp grad","PostgreSQL","Marketo","Salesforce","Hungry to learn","Willing to travel","Wordpress","HTML","CSS","Photoshop","Go lang","Elixir","Angular","ElasticSearch","Angular.js","Entry level","Security","Penetration testing","Non-profit experience","Supply chain","Logistics","US Military Veteran","Executive Assistant","Graphic Design","C#","Gaming",".NET","Mobile","Android","iOS","Swift","Kotlin","Git","Hadoop","Machine Learning","Data Science","Artificial Intelligence","SQL Server"];
foreach ($allTags as $tagName) {
Tag::findOrCreate($tagName, 'candidate');
}
}
}
@connor11528
Copy link
Author

Feel free to create a candidate profile on Employbl: https://employbl.com/candidates

Full Medium tutorial here: https://medium.com/employbl/build-tagging-with-vue-multiselect-and-laravel-tags-960c260df438

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment