Skip to content

Instantly share code, notes, and snippets.

View vineeth030's full-sized avatar

Vineeth Vijayan vineeth030

  • BEO
  • Kochi
View GitHub Profile
- Paying attention to consistency when naming things:
- Classes
- Methods
- Variables
- Routes
- Preventing spelling mistakes
- Preventing unsafe code
- Type hint method parameters
- Always include user input validation
- Add exception and error handling
<?php
public function boot()
{
Nova::serving(function () {
Post::observe(PostObserver::class);
});
}
<?php
/**
* Handle the post "creating" event.
*
* @param \App\Post $post
* @return void
*/
public function creating(Post $post)
{
<?php
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('Name'),
Text::make('Description'),
Tags::make('tags')
// I need an author_id field here.
@vineeth030
vineeth030 / custom_confirm_dialog_laravel_nova.vue
Last active July 5, 2020 09:10
The custom confirm dialog modal for Laravel Nova Tools
/* CustomModal.vue */
<template>
<modal tabindex="-1" role="dialog" @modal-close="handleClose">
<form @keydown="handleKeydown" @submit.prevent.stop="handleConfirm" class="bg-white rounded-lg shadow-lg overflow-hidden w-action">
<div>
<heading :level="2" class="border-b border-40 py-8 px-8">Confirm action</heading>
<p class="text-80 px-8 my-8"> Are you sure you want to perform this action? </p>
</div>
<div class="bg-30 px-6 py-3 flex">
<?php
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
"require": {
"php": "^7.2.5",
"fideloper/proxy": "^4.2",
"laravel/framework": "^7.0",
"laravel/nova": "*"
},
"repositories": [
{
"type": "path",
"url": "./nova"
}
],
<?php
// Add scope methods in model class
public function scopeConditionOne($query)
{
return $query->where('column_1', '=', 100);
}
public function scopeConditionTwo($query)
{
<?php
$results = User::where('column_1', '=', 100)
->where('column_2', '>', 200)
->where('column_3', '<', 350)
->where('column_4', '=', 400)
->where('column_5', '>', 150)
->get();