Skip to content

Instantly share code, notes, and snippets.

View whoisryosuke's full-sized avatar
👾
Going deep with game development

Ryosuke whoisryosuke

👾
Going deep with game development
View GitHub Profile
@whoisryosuke
whoisryosuke / laravel-middleware-specific-methods.php
Created May 15, 2018 23:53
Laravel - Apply Middleware in the Controller to "only" certain methods, or "except" certain methods.
<?php
public function __construct()
{
// Only apply middleware to these methods
$this->middleware('auth', ['only' => ['create', 'store', 'edit', 'delete']]);
// Or exclude middleware from these methods
$this->middleware('auth', ['except' => ['confirmPage', 'confirmOrder', 'invoice']]);
}
@whoisryosuke
whoisryosuke / laravel-loop-through-old-flash.php
Created May 16, 2018 23:58
Laravel - Get old form input values for array-based input
<?php
@if(old('uid_tag'))
@foreach(old('uid_tag') as $product)
<input type="text" name="uid_tag[]" value="{{ old('uid_tag')[$loop->index] }}" size="30" />
<textarea
placeholder="Include weight or count"
name="product_description[]"
cols="45"
rows="1"
value="{{ old('product_description')[$loop->index] }}"
@whoisryosuke
whoisryosuke / semantic-ui-basic-lightbox.html
Last active May 4, 2022 21:51
Semantic UI - Simple Image Lightbox using basic modal
<h2 class="ui header">Semantic UI Lightbox Example</h2>
<section class="ui stackable cards">
<figure class="PhotoCard ui card">
<img src="http://via.placeholder.com/300x250" class="ui fluid image">
<figcaption class="content">
Cool pics
</figcaption>
</figure>
</section>
<script>
@whoisryosuke
whoisryosuke / load-script-on-model-boot.php
Created May 18, 2018 22:00
Laravel - Add a hook script to the Model. In this case, we generate a UUID on creation.
/**
* Setup model event hooks
*/
public static function boot()
{
parent::boot();
self::creating(function ($table) {
// Generate uuid
$table->uuid = Uuid::generate(4);
});
@whoisryosuke
whoisryosuke / controller.php
Created May 30, 2018 23:57
Laravel Middleware - Apply middleware to specific controller methods (two ways!)
<?php
public function __construct()
{
// Apply middleware to only certain routes
$this->middleware('auth', ['only' => ['create', 'store', 'edit', 'delete']]);
// Or apply middleware to all routes except these
$this->middleware('auth', ['except' => ['index', 'show']]);
}
@whoisryosuke
whoisryosuke / laravel-api-resource-collection.php
Last active July 12, 2023 18:48
Laravel - API Resources - How to change the collection array that gets returned using the transform method
<?php
class PageResourceCollection extends ResourceCollection
{
public function toArray($request)
{
return [
'data' => $this->collection->transform(function($page){
return [
'id' => $page->id,
'title' => $page->title,
@whoisryosuke
whoisryosuke / ProjectController.php
Last active June 1, 2018 17:33 — forked from hanspagel/ProjectController.php
Laravel - API - How to return API Resources with different status codes
<?php
namespace App\Http\Controllers;
use App\Models\Project;
use Illuminate\Http\Request;
class ProjectController extends Controller
{
public function update(Request $request, Project $project)
@whoisryosuke
whoisryosuke / slugify.js
Created June 5, 2018 21:06 — forked from mathewbyrne/slugify.js
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@whoisryosuke
whoisryosuke / module.js
Last active June 5, 2018 21:20
NodeJS - CommonJS Module syntax using `require()` + `module.exports` (instead ES6 version `export default` and `import package from '/package/';) -- slugify credits: https://gist.github.com/mathewbyrne/1280286
module.exports = {
slugify: function(text) {
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
};
@whoisryosuke
whoisryosuke / css-flexbox-reorder-content-on-mobile.html
Created June 5, 2018 21:46
CSS - Flexbox - Reorder content -- (e.g. Move sidebar under content if it's hardcoded above it in HTML)
<style>
@media (max-width: 800px) {
.container {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;