Laravel Multiple Login Logout Password Reset User/Member and Admin Tutorial

When you work in CMS, it is pretty common you have multiple roles and permission.

Setting Up Multi-Authentication in Laravel 5.4+ (Part 1)

Or from Forum

https://laracasts.com/discuss/channels/laravel/password-reset-for-multiple-tables?page=1

However, for my own appoach kind of different from above solution.

I am using subdomain to different out the session. So I do no need to duplicate the controller. I can use the same flow as main domain used.

 

Convert Excel Text Number String to Number for calculating used

I am sure you experience after export from some software. The number treated as String. And you can’t use it for doing calculation.

  1. Copy the data to new sheet or new workbook.
  2. paste in this formular `=IF(ISBLANK(B2),””,VALUE(B2))`
    What this formular do is first check is the cell is it blank or not, if it is blank then show it is blank, else, show the value of that cell (this is the part convert it from string to number)
  3. Next, you just copy and paste the formula accordingly.
  4. Final step, you select all the formular area, then paste it as VALUE.
  5. DONE!

Below example, as you can see the yellow part is original data, it mixed with string and number. The little green arrow on the top left corner indicate you can convert it to other format, but you have to do it one by one.

On the green part is followed by formular converted it to number.

 

Thanks for reading!

Laravel Validation required keep throw exception the given data invalid.

My Laravel Project happen something strange that, basic Laravel Validation for Required Rule not working correctly. It really drives me crazy…
It keeps throwing the below error:-
Illuminate \ Validation \ ValidationException
The given data was invalid.
Finally I found out it is due to I implemented the new Laravel Whoops with IDE Integration.
I use below code.
https://gist.github.com/adampatterson/1c01aec54ebce7632bddd9e9e8566a65#file-sample-php
In my app/Exceptions/Handler.php
the render() method.
if (config('app.debug') && app()->environment() != 'production') {
    return $this->handleWhoopsies($request, $exception);
}
At this moment I just remove the support for the IDE. Keep thing simple.

Laravel composer fork project for urgent own use

Nowadays, we definitely using other people packages in own project. What if you found a bug or special workflow to suit your own need. But the project owner didn’t accept the pull request or them didn’t maintenance the project anymore.

If you brave enough you can fork it and continue maintaining it. So people can continue with your repo.

However, I don’t think it is the common use case. So what should you do? Thank God, it has an easy fix in your composer.

First, you, of course, need to fork the project. Then create a branch name start with dev- ,e.g  dev-fix-something then do whatever you need then commit to your repo.

Correction: You just create a branch with the feature you need e.g fix-route.  Composer will auto added the prefix. If you added your own dev-xxx, you will have included  duplicated e.g dev-dev-xxxx

This is why all the master branch it is named as dev-master.

In your composer.json file. add the follow lines. Can be before require tag:

"repositories": [{
  "type": "vcs",
  "url": "https://github.com/my-name/awesomeproject"
}],

Then in the require tag, u need to change original package repo to your new branch.

"require": {
    "php": ">=7.0.0",
    "pro-developer/awesomeproject": "dev-fix-something",

Save your composer.json file. Then go to Terminal run composer update

Then you should be using your own fix branch. If the repo owner finally accepted your pull request, then you can switch back to the original require version.

Note:

If you somehow run the composer update got error like below:-

Your requirements could not be resolved to an installable set of packages.

Problem 1
The requested package pro-developer/awesomeproject dev-fix-something exists as pro-developer/awesomeproject[0.1, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.4.1, 1.0.5, 2.0, 2.0.1, 2.0.10, 2.0.12, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, 3.0, 3.0.1, 3.0.10, 3.0.11, 3.0.12, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.0.6, 3.0.7, 3.0.8, 3.0.9, 3.1, 3.1.1, 3.1.10, 3.1.11, 3.1.12, 3.1.2, 3.1.3, 3.1.4, 3.1.4.1, 3.1.6, 3.1.7, 3.1.8, 3.2.0, 3.2.1, 3.2.2, 3.3.0, 3.3.1, 3.3.2, 4.0, 4.0.1, 4.0.10, 4.0.11, 4.0.12, 4.0.2, 4.0.3, 4.0.4, 4.0.5, 4.0.6, 4.0.7, 4.0.8, 4.0.9, 4.1, 4.1.1, 4.1.10, 4.1.11, 4.1.12, 4.1.2, 4.1.23, 4.1.3, 4.1.4, 4.1.5, 4.1.6, 4.1.7, 4.1.8, 4.1.9, 5.0.0, dev-dev-fix-something] but these are rejected by your constraint.

You could be gotten wrong branch name. In the above example the correct name should be dev-dev-fix-something, just make the changes in your composer.json then you can ready to run composer update again. It should be working fine.

After the composer update, you can run composer show -v pro-developer/awesomeproject to see the details. You should be to see the support source is from your own repo.

That’s all. Thanks for reading. Happy Coding! Make more great open source project and contribute more to the community.

open edit from cmd like notepad++, sublime or atom

If you come from Mac or Linux. When you want to edit a program. You can easily use console editor to edit the file.

e.g vi /etc/hosts so you can edit the hosts file.

But how you able to do it in Windows. Previously, I need to go to the Windows Explorer, go to that path and then open notepad drag and drop (If you turn off User Account Control Settings – which is not recommended by Windows). Kind of many step to do…

The easy way to accomplished is using below command. I assumed you had installed notepad++

start notepad++ composer.json

In this way, you able to open the file directly from notepad++ or other editor you like.

Please be reminder you only can do so, if you editor had added into SYSTEM ENVIRONMENT PATH.

Tips: Another good cmd alternative in windows I am using https://conemu.github.io/

runcloud use two projects sharing the same media folder

If you have a chance using symlink in your project. E.g your media folder. You might be using a symlink to reference the same media directory.

When I deploy my project to live. I keep hitting `Cannot save image intervention image. NotWritableException in Image.php line 138`

I am sure I am using the same owner for both directories. However it kind of weird to having this error message.

Then I started to trace the path. I tested with andFile::isDirectory File::iswritable. Then I was having open_basedir restriction in effect. File(/) is not within the allowed path(s):

Then this made me proceed to next checking.Finally, I found out this OPEN_BASEDIR issue.

In runcloud they had provided OPEN_BASEDIR for security purpose.

So what you have to do is include your another project repo into. And they have warned you about the risk. Make sure you know what you are doing.

Laravel Valet with SubDomain

In order to allow to use Laravel Sub Domain Route in Your Laravel Valet.

Let’s say my project folder name is ‘forum’. I would like the forum users to have their own public profile page via sub-domain.

Here is my route file:-

Route::domain('{account}.forum.dev')->group(function () {
    Route::get('user/{id}', function ($account, $id) {
        //
    });
});

In my Valet Folder. I need to use a symlink to archive the goal. In my case, I use Ken as a test user. Unfortunately, you can’t archive it via wildcard in Valet.

ln -s forum ken.forum

That’s all. Happy Coding

PHP Round Up to nearest Array

//array list
$array = array(1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 150, 250, 300, 350, 400, 450, 500, 600, 700, 800, 900, 1000);

//array round up function
function getArrayRoundUp($array, $number) {

sort($array);
foreach ($array as $a) {
if ($a >= $number) return $a;
}
return end($array);
}

//assume this is the value
$value = 904.5;

$nearest = getArrayRoundUp($array, $value);

//the expect result will be 1000
echo $nearest;

 

Laravel Valet for OpenCart 2.x using Custom Valet Drivers

Using Laravel Valet with OpenCart 2.x?

I am taking a while to understand how the valet custom driver work for my own OpenCart project.

1. My OpenCart project is located at ~/Sites/myshop (myshop is my folder name, it is very important how you name your driver)
2. Go to ~/.valet/Drivers/
3. Create a file name MyshopValetDriver.php
4. Template you can reference here. Laravel Valet for OpenCart 2.x
5. Tata, your Opencart now support SEO URL with Laravel Valet.

 

Valet Version: v2.0.5
Opencart Version: v2.3.0.2 (It will works on any Opencart 2.x version)

 

Vagrant Docker Windows 10 cannot ping from Host

If you notice after you restart your computer. Then you run vagrant up, and you can’t access to the vagrant image from the Windows 10 Vagrant Virtualbox with Docker Setup tutorial.

ping 192.168.33.10 there are no response….

What you can do is follow the below step to reactivate again.

  1. SSH to the vagrant machine using 127.0.0.1:2222
  2. sudo ip addr del 192.168.33.10/24 dev enp0s8 remove the enp0s8
  3. sudo brctl addif docker1 enp0s8 bridge the network again
  4. Tata~ now you can ping from your host machine again
  5. Done. Continue your docker development.

Thank you for reading.