Skip to content

Instantly share code, notes, and snippets.

View technoknol's full-sized avatar
🎯
Focusing

Technoknol technoknol

🎯
Focusing
View GitHub Profile
@technoknol
technoknol / Laravel eloquent where-group-and-whereor-sorting-orderby-search.php
Created May 23, 2017 09:26
Full pagination, searching, orderby and sorting in laravel eloquent model
<?php
// You may need to use this classes
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Pagination\Paginator;
// Searching in segments Model, with pagination, ordering, sorting and searching.
$segments = Segment::where('segmentProviderName', $provider); // first where condition
$segmentStatuses = config('constants.segment.status');
@technoknol
technoknol / Role.php
Created May 18, 2017 07:57
Model relation with other model in laravel
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
public $timestamps = false;
protected $primaryKey = 'roleId';
@technoknol
technoknol / pagination-in-laravel-5.4.php
Created May 17, 2017 05:06
Pagination in Laravel 5.4
<?php
$currentPage = 3; // You can set this to any page you want to paginate to
// Make sure that you call the static method currentPageResolver()
// before querying users
Paginator::currentPageResolver(function () use ($currentPage) {
return $currentPage;
});
@technoknol
technoknol / custom validator in laravel to validate comma separated emails.php
Created May 5, 2017 08:28
custom validator in laravel to validate comma separated emails.
<?php
// custom validator in laravel to validate comma separated emails.
\Validator::extend("emails", function($attribute, $values, $parameters) {
$value = explode(',', $values);
$rules = [
'email' => 'required|email',
];
if ($value) {
foreach ($value as $email) {
@technoknol
technoknol / log4php-for-laravel.php
Created May 4, 2017 13:04
Working log4php in Laravel (5.4)
<?php
// Middleware:
// app\Http\Middleware\log4php.php
namespace App\Http\Middleware;
use Closure;
class log4php
{
@technoknol
technoknol / helper-function-in-laravel-composer.json
Created May 3, 2017 12:36
Create helper function file in Laravel
// Add "files" element and give path of file there
// Do not forget to fire command 'composer dump-autoload'
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
},
@technoknol
technoknol / laravel-override-vendor-directory-classes-composer.json
Created May 2, 2017 12:21
Override vendor directory classes - Composer, Laravel
// In composer file exclude file that you want to override.
// composer.json
// I'm on windows machine so directory separator is \
// If you are on ubuntu/mac it should be like vendor/tymon/jwt-auth...
// Tymon is main name space for package, overrides is new folder I have created and copy pasted every files from vendor/tymon
// Then remove each file except you wanna override. Maintain folder structure.
"exclude-from-classmap": ["vendor\\tymon\\jwt-auth\\src\\Middleware\\BaseMiddleware.php"],
"psr-4": {
"App\\": "app/",
"Tymon\\": "app/overrides/"
@technoknol
technoknol / Enable CORS in Laravel 5.4.php
Created April 26, 2017 14:10
Enable CORS in laravel 5.4
<?php
# File: app\Http\Middleware\CORS.php
# Create file with below code in above location. And at the end of the file there are other instructions also.
# Please check.
namespace App\Http\Middleware;
use Closure;
class CORS {
@technoknol
technoknol / httpd-vhosts.conf
Created April 24, 2017 07:04
httpd-vhosts.conf configuration for laravel for windows and hosts file..
# Add below section to below httpd-vhosts.conf file.
# C:\xampp\apache\conf\extra\httpd-vhosts.conf
# And restart apache. (Make sure to change paths accordingly)
# Then you can navigate laravel from http://project.x
<VirtualHost project.x:80>
DocumentRoot "C:\xampp\htdocs\_projects\projectx\public"
ServerName project.x
ServerAlias project.x
ServerAdmin admin@localhost
@technoknol
technoknol / users_migration_and_database_seeder.php
Created April 20, 2017 09:18
Lumen 5.4/Laravel 5.4 Users migration and database Seeder
<?php
// Migration file
// database\migrations\create_users_table.php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{