Snippets Collections
$this->assertSame('FooBar', Str::reverse('raBooF'));
$this->assertSame('Teniszütő', Str::reverse('őtüzsineT'));
$this->assertSame('❤MultiByte☆', Str::reverse('☆etyBitluM❤'));
//original
$dotted = [
    'user.name' => 'foo',
    'user.occupation' => 'bar',
];
 
// Converts it back to the original form
Arr::undot($dotted);

// Results in...
$resultArray = [
    'user' => [
        'name' => 'foo',
        'occupation' => 'bar',
    ]
];
$original = [
    'user' => [
        'name' => 'foo',
        'occupation' => 'bar',
    ]
];
 
$dotted = Arr::dot($original);
 
// Results in...
$dotted = [
    'user.name' => 'foo',
    'user.occupation' => 'bar',
];
Event::fakeExcept([
    NonImportantEvent::class,
    'non-fake-event',
]);
$schedule->command('model:prune', [
    '--exclude' => [Test::class, Example::class],
])->daily();
export $(sudo cat /opt/elasticbeanstalk/deployment/env) && sudo -E -u webapp php artisan tinker
php artisan cache:clear
php artisan route:clear
php artisan config:clear 
php artisan view:clear 
Update your /app/Providers/AppServiceProvider.php to contain:

use Illuminate\Support\Facades\Schema;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Schema::defaultStringLength(191);
}
// in terminal, php artisan to create middleware
php artisan make:middleware VerifyIsAdmin

// in VerifyIsAdmin middleware file
public function handle(Request $request, Closure $next)
{
  if (!auth()->user()->isAdmin()) {
    return redirect()->back();
  }
  return $next($request);
}

// must register in kernel.php
protected $routeMiddleware = [
  'auth' => \App\Http\Middleware\Authenticate::class,
  'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
  'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
  'can' => \Illuminate\Auth\Middleware\Authorize::class,
  'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
  'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
  'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
  'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
  'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
  'verifyCategoryCount' => VerifyCategoriesCount::class,
  'admin' => VerifyIsAdmin::class,
];

// use in Route to ensure user is authenticated and admin
Route::middleware(['auth', 'admin'])->group(function () {
    Route::get('users', [UsersController::class, 'index'])->name('users.index');
});
// class ExampleRequest 
public function response(array $errors): RedirectResponse
{
  return Redirect::back()->withErrors($errors)->withInput();
}
<!-- form.blade.php -->
<div class="form-group col-md-6 mb-3">
   <label for="contact_lastname">Nom <span class="text-danger">*</span></label>
   <input type="text"
          class="form-control @if($errors->has('contact_lastname')) is-invalid @endif"
          id="contact_lastname" name="contact_lastname"
          aria-describedby="validation_contact_lastname">
   @if($errors->has('contact_lastname'))
   <div id="validation_contact_lastname" class="invalid-feedback">
     {{$errors->first('contact_lastname') }}
   </div>
   @endif
</div>

<!-- ContactsController.php -->
$request->validate([
   'contact_lastname' => 'required'
]);
composer require laravel/sail --dev
php artisan sail:install
./vendor/bin/sail up
// Create 5 documents
$documents = Document::factory()->count(5)->make();

// Create contact
$contact->documents()->saveMany($documents);
$response = $response->withHeader('x-joey-test', 'myvalue');

return $response->withStatus(404)->getBody()->write('not found');
return $response->getBody()->write('hello world');
// convention is to make table name singular and in alphabetical order
php artisan make:migration create_post_tag_table

// create_post_tag_table.php
// if 1 post has 5 tags, then 5 records will exist with same post_id and different tag_ids
public function up()
{
  Schema::create('post_tag', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->integer('post_id');
    $table->integer('tag_id');
    $table->timestamps();
  });
}

// Post.php
// define relationship in Post model
public function tags()
{
  return $this->belongsToMany(Tag::class);
}
// php artisan make:seeder NameOfTheSeeder

<?php

namespace Database\Seeders;

use App\Models\ModelName;
use Illuminate\Database\Seeder;

class ModelNameSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        ModelName::factory()->count(50)->create();
    }
}
/**
 * Carbon example for january 2021 
 */

// first day of month (2021-01-01 00:00:00)
Carbon::now()->firstOfMonth()->startOfDay()

// first day of month in timestamp (1609459200)
Carbon::now()->firstOfMonth()->startOfDay()->timestamp

// last day of month (2021-01-31 23:59:59)
Carbon::now()->lastOfMonth()->endOfDay()

// last day of month in timestamp (1640995199)
Carbon::now()->lastOfMonth()->endOfDay()->timestamp

/**
 * Carbon example for january 1, 2021 
 */

// start of day in date (2021-01-01 00:00:00)
Carbon::now()->startOfDay()
 
// start of day in timestamp (1609459200)
Carbon::now()->startOfDay()->timestamp
 
// end of day in date (2021-01-01 23:59:59)
Carbon::now()->endOfDay()
 
// end of day in timestamp (1609545599)
Carbon::now()->endOfDay()->timestamp
Route::middelware(['auth'])->group(function (){

    Route::get('/', function () {
        return view('welcome');
    });

    Route::get('/dashboard', function (){
        return view('dashboard');
    })->name('dashboard');

});
Route::patch('aluminio/{id}', 'AluminioController@update')->name('aluminio.update');
$tasks = Tasks::find(1);
$newTask = $tasks->replicate();
$newTask->save();
//Multiple relationships:
$books = Book::with('author', 'publisher')->get();

//Nested relationships:
$books = Book::with('author.contacts')->get();
<!-- use enctype -->
<form  action="/route" method="POST" enctype="multipart/form-data">
class="{{ Request::is('products.index') ? 'active' : '' }}"
// url : https://www.example.com/param1/param2/param3
$request()->segment(3); // param3
// config/app.php
'locale' => 'fr',
'fallback_locale' => 'fr',
// replace get()
$products = Product::where('active', 1)->get();

// by paginate()
$products = Product::where('active', 1)->paginate(10);
// config\database.php
'connections' => [
    'mysql' => [
      (...)
      'strict' => true,
    ],
],
$this->validate($request, [
	"field_nullable" => "nullable"
]
/**
* Artisan Command
*/

php artisan make:request RequestName

/**
* Controller Code
*/
// inject filepath to custom request
use App\Http\Requests\RequestName;

// inject custom request as $request
// $request knows about validation and will automatically validate
public function store(RequestName $request)
    {
        Category::create([
            'name' => $request->name
        ]);

        session()->flash('success', 'Category Successfully Created');

        return redirect(route('categories.index'));
    }
    
/**
* Request File
*/
class CreateCategoryRequest 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()
    {
    // this is where validation rules are set
        return [
            'name' => 'required|unique:categories'
        ];
    }
}
if (str_contains(url()->current(), '/api')) {

            $finalProperty = [];
            $properties = PropertyListing::orderBy('id', 'DESC')->get(["id","user_id","listing_for","images","address","price","property_type","furnishing_status","facilities"]);
            foreach ($properties as $key => $property){
                // $finalImage['id'] = $property->id;
                // $finalImage['user_id'] = $property->user_id;
                // $finalImage['listing_for'] = $property->listing_for;
                $img_array = explode(',',$property->images);

                $properties[$key]->images = $img_array;

            }
         
            return response()->json(['properties' => $properties, 'success' => 200]);
            
        } else {
            $sliderImages = PropertyListing::all();
            return view('admin.imageslider.index', compact('sliderImages'));
        }
\Log::info(print_r($siteImageUrl, true));
php artisan migrate:refresh --path=/database/migrations/my_migration.php
NotificationFactory::new()->create();



use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Support\Str;

class NotificationFactory extends Factory
{
    protected $model = DatabaseNotification::class;

    public function definition()
    {
        return [
            'id' => Str::uuid()->toString(),
            'type' => 'App\Notifications\ThreadSubscription',
            'notifiable_id' => function() {
                return auth()->id() ?? User::factory()->create();
            },
            'notifiable_type' => 'App\Models\User',
            'data' => ['message' => 'text']
        ];
    }
}
* Start the VM
	- vagrant up
	- vagrant ssh
* Shutdown and remove everything in memory
	- vagrant halt
* Close the VM for later use
	- vagrant suspend
	- vagrant resume
* Changed the homestead.yaml file?
	- vagrant provision
composer create-project "laravel/laravel=5.1.*" sampleproject
// sending a massage to blade from controller
return redirect()->route('add_item')->with('message', "Category Created Successfully");


//Checking for a message from the blade 
  @if(session()->has('message'))
    <div class="alert alert-success">
        {{ session()->get('message') }}
    </div>
@endif
$entities = $user->entities;
$entityIds = $entities->map( function($entity) {
    return [$entity['id']];
});
Entity::whereIn('id', $entityIds)->deleted();
php artisan cache:clear
chmod -R 777 storage/
composer dump-autoload
Route::group(['prefix' => '/user'], function () {
    Route::get('/profile', function(){
        return 'Profile';
    });

    Route::get('/password', function(){
        return 'Password';
    });
});
$validatedData = $request->validate([
    'name' => 'required',
    'gender' => 'required',
    'country' => 'required',
    'bod'=>'required',
    'description'=>'required',
]);

Profile::where('user_id',$user_id)->fill([
        'name'=>'name',
        'gender'=>'gender',
        'country'=>'country',
        'bod'=>'bod',
        'description'=>'description',
    ])->save();
Hello, As I read in your description that your company has many php- laravel, javascript projects, I am very interested in working with you. As you can see my profile, I have worked in core PHP, php and wordpress and javascript many times. I can work in this domain.
I know MVCs very well and have experience with them. I have worked with MVC CRUD, routing, integrating frontend technologies like vue.js and angular.js with the MVCs.
I have spent time in Integrating payment gateways in php and laravel.
I am also quiet good in architecturing databases like MySQL.
So overall I feel I will be a great fit t your system if selected once for a project.
If any thing is new for me that has to be implemented in the project then I find it to be a great opportunity of learning and implementation. So you can trust me and keep me as your working partner. You wil find me as a basic need of your development team after I have spent some time working with youl.
I will be waiting for your response.
Thank you.
Kind Regards.
public function update(Request $request, $id)
    {
        $this->validate($request, [
            'name' => 'required|unique:categories',
        ]);

        $category = Table::findOrFail($id);
        $category->name = $request->name;
        $category->save();
        return redirect()->route('management.table.home')->with('message', "Table Edited Successfully");
    }
   User::create([
           'name' => $request->name,
           'username' => $request->username,
           'email' => $request->email,
           'password' => Hash::make($request->password),

        ]);
<form action="{{ route('posts.likes', $post->id) }}" type="submit" method='post' >
                  @csrf
                  @method('delete')
                <button  type="submit" class="btn btn-primary btn-sm">Dislike</button>
              </form>

//route
Route::delete('/posts/{id}/likes', [PostLikeController::class, 'destroy'])->name('posts.likes');
// In post model are we are checking whether user has liked it:
// contains is a collection method which allows to look at the inside of the collection
// with collectiong you are looking at a particular key (user_id), and checking if the $user->id is within the collection
// then it will return a true or false
 
// POST MODEL: 
public function likedBy(User $user){
      return $this->likes->contains('user_id', $user->id);
    }

//POSTLIKECONTROLLER
 public function store($id, Request $request){
// this is activating when you press the submit button for like

        $this->middleware(['auth']);


        $post = Post::find($id);

        if ($post->likedBy($request->user())){
            return back(); 
        }
        
        $post->likes()->create([
            'user_id' => $request->user()->id,
        ]);
        return back();




 {{ Str::plural('like', $post->likes->count()) }}
public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required|unique:categories',
        ]);

        Category::create([
            'name' => $request->name,
        ]);
Route::get('/',closure)
<button type="submit" id="customers_filter" onclick="checkWhetherTheTableContainsSearchResults()"
                                class="btn filter-button d-inline-block ml-3">
                                Filter
                            </button>
                            
<input id="search-hidden-input" hidden name="searchValue">

<script>
function checkWhetherTheTableContainsSearchResults() {
        let search = location.search.substring(1)
            searchInputElement = document.getElementById('search-hidden-input');
        
        if(search != '') {
            searchInputElement.setAttribute('value', search);
        }
    }
</script>
    
// If the filter is to work on search results, the original search parameter has to be passed into the request array.
        // Thus, the request array will return more than one parameter 
        // AND
        // one of the parameters will be searchValue
        // WHICH
        // will contain the entire search parameter (key + value)

        if ((count($request->all()) > 1) && (isset($request->searchValue))) {
            if (strpos($request->searchValue, '=')) {
                $string = $request->searchValue;
                $array = explode('=', $string);
                $request->searchValue = $array[1];
            }
        }
"repositories": {
        "webdevmatics/jetstream" : {
            "type": "path",
            "url": "C:\\laragon\\www\\codegenerator\\packages/webdevmatics/jetstream"
        }
    }
star

Thu Dec 02 2021 08:07:22 GMT+0000 (UTC) https://laravel-news.com/laravel-8-74-0

#php #laravel
star

Thu Dec 02 2021 08:04:47 GMT+0000 (UTC) https://laravel-news.com/laravel-8-74-0

#php #laravel
star

Thu Dec 02 2021 08:00:24 GMT+0000 (UTC) https://laravel-news.com/laravel-8-74-0

#php #laravel
star

Thu Dec 02 2021 07:54:36 GMT+0000 (UTC) https://laravel-news.com/laravel-8-74-0

#php #laravel
star

Thu Dec 02 2021 07:50:26 GMT+0000 (UTC) https://laravel-news.com/laravel-8-74-0

#php #laravel
star

Thu Dec 02 2021 07:47:42 GMT+0000 (UTC) https://laravel-news.com/laravel-8-74-0

#php #laravel
star

Wed Nov 24 2021 19:03:48 GMT+0000 (UTC) https://stackoverflow.com/questions/61816556/laravel-artisan-tinker-from-amazon-linux-2-elastic-beanstalk

#php #elasticbeanstalk #laravel
star

Thu Nov 18 2021 20:18:27 GMT+0000 (UTC) https://stackoverflow.com/questions/42244541/laravel-migration-error-syntax-error-or-access-violation-1071-specified-key-wa

#php #laravel
star

Thu Nov 18 2021 02:32:53 GMT+0000 (UTC)

#php #laravel
star

Fri Oct 29 2021 04:36:51 GMT+0000 (UTC) https://laravel.com/docs/8.x/middleware

#php #laravel
star

Tue Oct 19 2021 15:45:06 GMT+0000 (UTC)

#laravel
star

Tue Oct 19 2021 14:30:52 GMT+0000 (UTC)

#laravel
star

Wed Oct 13 2021 21:32:30 GMT+0000 (UTC)

#laravel
star

Tue Oct 05 2021 20:40:04 GMT+0000 (UTC)

#laravel
star

Fri Sep 24 2021 17:36:04 GMT+0000 (UTC)

#php #laravel
star

Wed Sep 01 2021 03:03:27 GMT+0000 (UTC) https://stackoverflow.com/questions/43187735/laravel-5-4-create-model-controller-and-migration-in-single-artisan-command

#انشاءموديول وكنترول وملف ميجريشن #cmd #laravel
star

Fri Jul 30 2021 00:28:21 GMT+0000 (UTC) https://laravel.com/docs/8.x/eloquent-relationships#many-to-many

#php #laravel
star

Thu Jun 24 2021 20:46:42 GMT+0000 (UTC)

#laravel
star

Thu Jun 17 2021 19:33:02 GMT+0000 (UTC)

#laravel
star

Fri Jun 11 2021 21:12:23 GMT+0000 (UTC) https://dev.to/jeromew90/how-use-sweetalert2-in-laravel-8-using-composer-jki

#laravel
star

Fri Jun 11 2021 21:12:02 GMT+0000 (UTC) https://dev.to/jeromew90/how-to-create-a-multilingual-project-in-laravel-internationalization-i18n-11ol

#laravel
star

Fri Jun 11 2021 21:03:44 GMT+0000 (UTC)

#laravel
star

Fri Jun 11 2021 20:56:52 GMT+0000 (UTC)

#php #laravel
star

Fri Jun 11 2021 20:54:44 GMT+0000 (UTC)

#php #laravel
star

Fri Jun 11 2021 20:53:36 GMT+0000 (UTC)

#php #laravel
star

Sun May 16 2021 17:42:10 GMT+0000 (UTC) https://laravel.com/docs/8.x/validation#form-request-validation

#laravel
star

Mon Apr 19 2021 06:15:12 GMT+0000 (UTC)

#laravel
star

Tue Apr 06 2021 20:22:31 GMT+0000 (UTC) https://www.google.com/search?q

#php #laravel
star

Tue Apr 06 2021 12:42:54 GMT+0000 (UTC) https://stackoverflow.com/questions/47151886/how-can-i-run-specific-migration-in-laravel

#laravel #php
star

Sat Mar 20 2021 06:03:45 GMT+0000 (UTC)

#commandline #laravel
star

Wed Mar 17 2021 08:33:26 GMT+0000 (UTC) https://qiita.com/revenue-hack/items/f90fa5a7d4352d0bbc3f

#laravel #php
star

Fri Mar 12 2021 12:42:08 GMT+0000 (UTC)

#laravel
star

Thu Mar 11 2021 06:41:43 GMT+0000 (UTC) https://laracasts.com/discuss/channels/eloquent/how-to-delete-multiple-records-using-laravel-eloquent

#laravel #php
star

Wed Mar 10 2021 19:39:41 GMT+0000 (UTC) https://es.stackoverflow.com/questions/177114/cómo-redirigir-a-un-usuario-según-su-rol-en-laravel

#rol #laravel
star

Tue Mar 09 2021 14:34:57 GMT+0000 (UTC) https://stackoverflow.com/questions/36460874/laravel-5-errorexception-failed-to-open-stream-permission-denied

#laravel
star

Fri Feb 26 2021 13:51:51 GMT+0000 (UTC)

#laravel
star

Thu Feb 18 2021 15:22:20 GMT+0000 (UTC) https://stackoverflow.com/questions/57985564/laravel5-8-the-get-method-is-not-supported-for-this-route-supported-methods-p

#php #save #laravel
star

Fri Jan 15 2021 13:28:09 GMT+0000 (UTC)

#php #laravel
star

Mon Jan 11 2021 19:39:41 GMT+0000 (UTC)

#laravel
star

Thu Dec 31 2020 11:35:22 GMT+0000 (UTC)

#laravel
star

Mon Dec 28 2020 13:06:02 GMT+0000 (UTC)

#laravel
star

Mon Dec 28 2020 10:39:10 GMT+0000 (UTC)

#laravel
star

Sun Dec 27 2020 11:56:53 GMT+0000 (UTC)

#laravel
star

Sun Dec 27 2020 08:06:01 GMT+0000 (UTC)

#laravel
star

Fri Dec 11 2020 14:49:35 GMT+0000 (UTC) https://www.hoclabs.com/2018/01/14/laravel-roles-y-permisos/

#roles #laravel
star

Tue Dec 01 2020 00:27:14 GMT+0000 (UTC)

#laravel
star

Thu Nov 26 2020 18:43:15 GMT+0000 (UTC) https://virtumedia.wordpress.com/2020/02/27/generar-documentos-pdf-en-laravel-que-incluyan-graficos/

#pdf #laravel
star

Tue Nov 10 2020 15:39:18 GMT+0000 (UTC) https://es.stackoverflow.com/questions/218143/envio-de-mail-con-archivo-adjunto-laravel

#email #laravel
star

Fri Oct 02 2020 03:24:40 GMT+0000 (UTC)

#php #laravel

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension