git clone [this repo.git]:
git clone https://github.com/Bazsmagister/bicycle_7.7.1.git
composer install
cp .env.example .env
// edit your database settings in .env file
php artisan key:generate
admin@admin.com : adminadmin servicesergey@service.com : serviceservice servicesebastian@service.com : serviceservice authuser@authuser.com : authuser sale@sale.com : salesale
composer require laravel/ui answer: Using version ^2.0 for laravel/ui
shift+ctrl+6 = comment/uncomment html great!!!
php artisan ui vue --auth
npm install && npm run dev
npm run watch or npm run watch-poll
php artisam make:model Bicycle -a it creates: Model created successfully. Factory created successfully. Created Migration: 2020_04_22_075710_create_bicycles_table Seeder created successfully. Controller created successfully.
I don't want to use timestamps: public $timestamps = false; otherwise in factory: 'created_at' => now(), 'updated_at' => now(),
and in migrations use: $table->timestamps();
I don't want to protect against mass assiggnement (for a while...) protected $guarded = [];
migration: $table->string('name'); $table->timestamp('bicycle_broughtIn_at')->nullable(); $table->timestamp('bicycle_startedToServiceIt_at')->nullable(); $table->timestamp('bicycle_readyToTakeItHome_at')->nullable();
relative path to faker: vendor/fzaninotto/faker/src/Faker/Generator.php
$factory->define(Bicycle::class, function (Faker $faker) { return [ 'name' => $faker->unique()->word, 'bicycle_broughtIn_at' => $faker->dateTimeBetween('yesterday', '-25 hours'), 'bicycle_startedToServiceIt_at' => $faker->dateTimeBetween('yesterday', '-1 hours'), 'bicycle_readyToTakeItHome_at' => now(), ]; });
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=bicycle DB_USERNAME=u DB_PASSWORD=u
sudo mysql create database bicycle;
$this->call(UserSeeder::class);
$this->call(BicycleSeeder::class);
factory(App\Bicycle::class, 10)->create();
php artisan make:seeder UserSeeder;
factory(App\User::class, 10)->create();
composer dump-autoload
The [/home/bazs/code/bicycle_7.7.1/public/storage] link has been connected to [/home/bazs/code/bicycle_7.7.1/storage/app/public]. The links have been created.
Scaffold the authentication controllers
php artisan make:component Alert
The make:component command will place the component in the App\View\Components directory. The make:component command will also create a view template for the component. The view will be placed in the resources/views/components directory.
php artisan make:component Alert --inline public function render() { // return <<<'blade' //
spatie/laravel permission
or: php artisan make:model Permission -m php artisan make:model Role -m
php artisan make:migration create_permission_user_table --create=permission_user
php artisan make:migration create_role_user_table --create=role_user
php artisan make:seeder RolesTableSeeder
php artisan make:seeder PermissionTableSeeder
php artisan make:migration create_permission_role_table --create=permission_role
app/Role and app/Permission make the methods. belongsToMany
trait: app/Permissions/HasPermissionsTrait.php
User.php use App\Permissions\HasPermissionsTrait;
composer dump-autoload
his package can be used in Laravel 5.8 or higher.
composer require spatie/laravel-permission
//Using version ^3.13 for spatie/laravel-permission
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
/Copied File [/vendor/spatie/laravel-permission/config/permission.php] To [/config/permission.php] Copied File [/vendor/spatie/laravel-permission/database/migrations/create_permission_tables.php.stub] To [/database/migrations/2020_05_29_090505_create_permission_tables.php] Publishing complete./
php artisan make:seeder RolesAndPermissionsSeeder
in seeder.php: use Spatie\Permission\Models\Role; use Spatie\Permission\Models\Permission;
When you use the built-in functions for manipulating roles and permissions, the cache is automatically reset for you, and relations are automatically reloaded for the current model record:
$user->assignRole('writer'); $user->removeRole('writer'); $user->syncRoles(params); $role->givePermissionTo('edit articles'); $role->revokePermissionTo('edit articles'); $role->syncPermissions(params); $permission->assignRole('writer'); $permission->removeRole('writer'); $permission->syncRoles(params);
To manually reset the cache for this package, you can run the following in your app code:
app()->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions();
Or you can use an Artisan command:
php artisan permission:cache-reset
https://drawsql.app/templates/laravel-permission
Excluding Timestamps from JSON
If you want to exclude timestamps from JSON output of role/permission pivots, you can extend the Role and Permission models into your own App namespace and mark the pivot as hidden:
protected $hidden = ['pivot'];
Adding Timestamps to Pivots
If you want to add timestamps to your pivot tables, you can do it with a few steps: - update the tables by calling $table->timestamps(); in a migration - extend the Permission and Role models and add ->withTimestamps(); to the BelongsToMany relationshps for roles() and permissions() - update your User models (wherever you use the HasRoles or HasPermissions traits) by adding ->withTimestamps(); to the BelongsToMany relationshps for roles() and permissions()
It is generally best to code your app around permissions only. That way you can always use the native Laravel @can and can() directives everywhere in your app.
Roles can still be used to group permissions for easy assignment, and you can still use the role-based helper methods if truly necessary. But most app-related logic can usually be best controlled using the can methods, which allows Laravel’s Gate layer to do all the heavy lifting.
eg: users have roles, and roles have permissions, and your app always checks for permissions, not roles.
Spatie\Permission\PermissionServiceProvider::class,
https://docs.spatie.be/laravel-permission/v3/basic-usage/middleware/
in app\http\kernel 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class, 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class, 'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
Then you can protect your routes using middleware rules:
Route::group(['middleware' => ['role:super-admin']], function () { // });
Route::group(['middleware' => ['permission:publish articles']], function () { // });
Route::group(['middleware' => ['role:super-admin','permission:publish articles']], function () { // });
Route::group(['middleware' => ['role_or_permission:super-admin|edit articles']], function () { // });
Route::group(['middleware' => ['role_or_permission:publish articles']], function () { // });
You can protect your controllers similarly, by setting desired middleware in the constructor:
public function __construct() { $this->middleware(['role:super-admin','permission:publish articles|edit articles']); }
public function __construct() { $this->middleware(['role_or_permission:super-admin|edit articles']); }
in AuthServiceProvider $this->registerPolicies();
// Implicitly grant "Super Admin" role all permission checks using can()
Gate::before(function ($user, $ability) {
if ($user->hasRole('Super-Admin')) {
return true;
}
});
Spatie\Permission\PermissionServiceProvider::class,
in app\User.php class User extends Authenticatable implements MustVerifyEmail in: app/routes/web.php Auth::routes(['verify' => true]);
and simple in your method just call this:
$user->sendEmailVerificationNotification();
composer require unisharp/laravel-filemanager php artisan vendor:publish --tag=lfm_config php artisan vendor:publish --tag=lfm_public php artisan storage:link
Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'auth']], function () { \UniSharp\LaravelFilemanager\Lfm::routes(); });
http://127.0.0.1:8000/laravel-filemanager/demo
`
<iframe src="/laravel-filemanager" style="width: 100%; height: 500px; overflow: hidden; border: none;"></iframe> `defer doesn't work {{-- <script src="{{ asset('js/app.js') }}" defer></script> --}}
<script src="{{ asset('js/app.js') }}"></script>To fix it, simply remove the defer attribute from the script tag.
The defer attribute is a boolean attribute.
When present, it specifies that the script is executed when the page has finished parsing.
Note: The defer attribute is only for external scripts (should only be used if the src attribute is present).
#test jquery
<script type="text/javascript"> jQuery(document).ready(function(){ jQuery( "#ddtype" ).change(function() {
alert( "Handler for .change() called." );
});
});
multipart/form-data No characters are encoded. This value is required when you are using forms that have a file upload control
$data= $request->all(); echo "
"; print_r($data); //die;multi role blade :
https://docs.spatie.be/laravel-permission/v3/basic-usage/blade-directives/
As discussed in the Best Practices section of the docs, it is strongly recommended to always use permission directives, instead of role directives. but:
@hasanyrole('super-user|salesman|serviceman') @endhasanyrole
Blade doesn't recognise @hasanyrole any longer
"I changed some minor (content) things in a template, and did a "php artisan cache:clear" to make sure things would be visible. Since then, I see that blade is no longer parsing @hasanyrole and @endhasanyrole any longer. This is how the html of the page is outputted now.Next I did replace hasanyrole by hasrole (with only one role) and that worked. Then I replaced back the hasanyrole and everything kept working. I'm happy the error is gone, but a bit puzzled and disturbed by such strange behaviour. If anyone could give a hint where I should start looking if it would occur again, it's still welcome."
Check remote: git remote -v !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Steps to recreate 1.Did a fresh laravel install, configured the guards 'guards' => [ 'employee' => [ 'driver' => 'session', 'provider' => 'employees', ],
]
2.configured model namespace App\Company;
//use Eloquent as Model; use Spatie\Permission\Traits\HasRoles; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Database\Eloquent\SoftDeletes;
class Employee extends Authenticatable { use HasRoles; use SoftDeletes; use Notifiable;
public $table = 'employees';
const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at';
protected $dates = ['deleted_at']; protected $guard_name = 'employee';
3.After creating employee , I assign role
if ($employee==true) { $employee->assignRole($role); }
4.I create role and assign permissions
$role = Role::create(['guard_name' => 'employee', 'name' => $request->role_name]) $role->syncPermissions($request->permissions)
I use artisan to create permissions
php artisan permission:create-permission "manage_parameters" employee
On my blade file, I check for permission @can('manage_parameters','employee') <li class="pcoded-hasmenu "> </li> @endcan
@sokeno Author sokeno commented on Jan 18, 2019
Thanks @drbyte for your input, I actually got the fix for it, The fix was to get rid of any defined relationships on my Employee model and add protected $guard_name = 'employee'; , Thanks
Check role , check @hasanyrole @hasanyrole('super-admin|serviceman|salesman')
has any role
@elsehas not role
@endhasanyrolepublic function store(){ $imageName = time().'.'.request()->image->getClientOriginalExtension(); request()->image->move(public_path('images'), $imageName); }
then use
<embed src="{{ asset("images/$imageName")}}">
In controller@update I can change the folder where it saves the pics. storage/images...
.env !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! FILESYSTEM_DRIVER=public
form validation( with tailwind)
@error('name')
{{$message}}
@enderrorAn alternate solution is adding this to the links key in your config/filesystems.php file.
public_path('avatars') => storage_path('app/public/avatars'),
After adding that, then you can run the artisan command again, and it should work.
For the avatar validation, you can use the image rule instead of just file. The dimensions rule maybe be useful as well. Example:
'avatar' => [ 'image', 'dimensions:min_width=100,min_height=200', ],
HTML5 supports regexes, so you could use this:
pattern="[0-9.]+"Laravel image upload: https://www.larashout.com/laravel-image-upload-made-easy?fbclid=IwAR1LUIXC1dCLdXQP9F_Ha4sS-i94MFrfSwxpIy2uCF7mIMtsVTCOCxiX0J8
npm install bootstrap-sweetalert
$bicycle->is_availableToRent = 0; $bicycle->save();
Laravel Echo REDIS Pusher Channel:
- app\config\app.php uncomment : // App\Providers\BroadcastServiceProvider::class,
test: php artisan route:list GET|POST|HEAD broadcasting/auth Illuminate\Broadcasting\BroadcastController@authenticate
app\config\broadcasting.php 'default' => env('BROADCAST_DRIVER', 'null'), to log or redis or pusher: 'default' => env('BROADCAST_DRIVER', 'log'),
php artisan make:event BicycleUpdated
- in app\events\Bicycleupdated implements ShouldBroadcast contract(interface)
public function broadcastOn() { // return new PrivateChannel('channel-name'); return new Channel('orders'); }
web.php use App\Events\BicycleUpdated;
Route::get('/', function () { BicycleUpdated::dispatch(); //same as // event(new BicycleUpdated);
return view('welcome');
});
pas (php artisan serve) hit the route:
check app\storage\logs\laravel.log
[2020-06-12 10:22:30] local.INFO: Broadcasting [App\Events\BicycleUpdated] on channels [orders] with payload: { "socket": null }
- in BicycleUpdated.php if you define a public property than it will load in the broadcast.
artisan make:provider HelperServiceProvider in this register method:
public function register() { foreach (glob(app_path().'/Helpers/*.php') as $filename) { require_once($filename); } }
Make a Helpers folder in App root.
in app\config\app.php add to providers. App\Providers\HelperServiceProvider::class,
in composer.json: "autoload": { "psr-4": { "App\": "app/" }, "classmap": [ "database/seeds", "database/factories" ], "files": [ "app/Helpers/helpers.php" ] },
composer dumpautoload
echo php_ini_loaded_file();
php artisan make:notification InvoicePaid php artisan make:notification newBicycleToRent php artisan make:notification newServiceCreated //a new notification php is created.
public function via($notifiable) { // return ['mail']; return ['mail', 'database']; }
php artisan notifications:table php artisan migrate
php artisan make:command SendEmails app\Console\Commands\SendEmail.php
edit: crontab -e
list: crontab -l
delete/remove crontab -r
---everyminutes in crontab -e:
-
-
-
-
- 5stars php /home/bazs/code/bicycle_7.7.1/artisan schedule:run >> /home/bazs/code/bicycle_7.7.1/storage/logs/laravel_output.log 2>&1
-
-
-
composer require --dev barryvdh/laravel-ide-helper answer: Using version ^2.7 for barryvdh/laravel-ide-helper
php artisan clear-compiled
php artisan ide-helper:generate answer: A new helper file was written to _ide_helper.php
{ in Appserviceprovider.php: public function register() { if ($this->app->environment() !== 'production') { $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } } or: If you are using Laravel versions older than 5.5, add the service provider to the providers array in config/app.php:
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
}
idea from: https://www.itsolutionstuff.com/post/ajax-autocomplete-textbox-in-laravel-58-exampleexample.html
Route::get('autocomplete', 'UserController@autocomplete')->name('autocomplete');
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.1/bootstrap3-typeahead.min.js"> <script> var path = "{{ route('autocomplete') }}"; // $('input.typeahead').typeahead({ //works with class $('#autocomplete').typeahead({ //works with id source: function (query, process) { return $.get(path, { query: query }, function (data) { return process(data); }); } }); </script><!-- <h5>Autocomplete Search using Bootstrap Typeahead JS</h5> -->
<h5>Autocomplete Search using Bootstrap Typeahead JS</h5>
<input id="autocomplete" class="typeahead form-control" type="text" placeholder="Start typing...">
$result = shell_exec("python " . storage_path() . "/python/python.py 2>&1"); //this works echo($result);
$result2 = shell_exec("python " . public_path() . "/storage/python/python.py 2>&1"); //this works too
echo($result2);
$command ="python ".public_path() . "/storage/python/python.py";
// $command =public_path() . "/storage/python/python.py"; //need python
$proc = Process::fromShellCommandline($command, null, [])->mustRun()->
getOutput();
//getErrorOutput();
echo $proc;
Don't forget RegisterController middleware auth:guest!!!
$user->notify(new newServiceIsMade($service)); need to create a notify when a bike is brought in , started to service, or ready to take it home
$table->enum('status', ['pending','processing','completed','decline'])->default('pending'); $table->enum('status', ['accepted','repariring','ready','taken'])->nullable();
?? //use Illuminate\Notifications\Notifiable; class Service extends Model { //use Notifiable; ??
two scripts with fetch() the same url doesn't work in one script tag. one of them is async await. Why is that?