dimanche 2 août 2020

"Property [role] does not exist on this collection instance."

I have a method that checks if a role is equal to 1 and then sends back some data. The method looks like so:

 if($user->role == 1) {
                $dmca = Dmca::get()->take(5);

                $data = [
                    'status' => 200,
                    'data' => $dmca
                ];

                return response($data);
            } else {
                $dmca = Dmca::where('client', $request->user_id)->get()->take(5);

                $data = [
                    'status' => 200,
                    'data' => $dmca
                ];

                return response($data);
            }
        }

On the dump and die of the $user instance, you can see the role is there and is set. But on return, I get the error

#attributes: array:11 [
        "id" => 1
        "name" => null
        "email" => "Grahammorbydev@gmail.com"
        "model_name" => "man"
        "subscribed" => 0
        "email_verified_at" => null
        "password" => "$2y$10$yy1Yj.GGez7efEdFdkjaf.RlQS17Zc7QYUANz3RvdE00fVm0f9AYq"
        "role" => 1
        "remember_token" => null
        "created_at" => "2020-07-05 17:54:38"
        "updated_at" => "2020-07-05 17:54:38"
      ]
     

Getting the following error when the axios returns

"Property [role] does not exist on this collection instance."


via Chebli Mohamed

How to paginate data from complex relations

I'm getting data from a Belongstomany relationship and I'm running the paginate helper on it but it doesn't seem to work. Here's my code..

$transactions  = User::withAndWhereHas('drinks', function($query) use ($status){
$query->where('status', '1');
})->paginate(10);


via Chebli Mohamed

PHP - Remove text between two slashes from URL

Consider the following URL in PHP:

monitor/2020-05/auto-1589457895-399-9042888978.wav

And I want following output:

 monitor/auto-1589457895-399-9042888978.wav

How can I remove the middle part from URL ?



via Chebli Mohamed

Laravel assets return 404 on localhost

I am pretty new to Laravel. I use Ubuntu and cloned an app from GitHub on home folder. When I run the app with php artisan serve I don't see the page styled. Ctrl-u shows the source with no problem but I have 404 errors in the console regarding everything under the asset folder. console warnings can be seen here

my 000_default.conf file is

/etc/apache2/sites-enabled/000-defult.conf                 
<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot ~/_/www/easymove/public

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/laravel>
                AllowOverride All
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>


Contents of the webpack.mix.js at the app root are as follows:

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css');


via Chebli Mohamed

ErrorException htmlspecialchars() expects parameter 1 to be string, object given ()

My controller

   public function total_record()
{
   $tailor_measurement=DB::select('select count(*) from tailor_measurement ');
    return view('total record',['tailor_measurement'=>$tailor_measurement]);
  
}

My view total record

<!DOCTYPE html>
<html>
<head>
<title>Total Records</title>
</head>
<body>
 @foreach($tailor_measurement as $row)
 
@endforeach
</body>
</html>

It give me error htmlspecialchars() expects parameter 1 to be string, object given (View: C:\wamp64\www\shaban\resources\views\total record.blade.php)



via Chebli Mohamed

contents of components not updating on frontend vue.js in Laravel

I have a component when i change the content of that component it does not reflect on the browser, for that i'm running

npm update

but i'm getting following error:

npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name "itor/ckeditor5-build-clas@ckedsic": name can only contain URL-friendly characters



via Chebli Mohamed

How to solve Script php -r "copy('.env.example', '.env');" handling the post-root-package-install event returned with error code 1

I tried to create a project using this command in git bash

composer create-project --prefer-dist laravel/laravel cms 5.2.29

then I got an error that is

Error:

** Creating a "laravel/laravel" project at "./cms" Installing laravel/laravel (v5.2.29)

  • Installing laravel/laravel (v5.2.29): Loading from cache Created project in C:\xampp\htdocs\cms

php -r "copy('.env.example', '.env');"

'php' is not recognized as an internal or external command, operable program or batch file.

Script php -r "copy('.env.example', '.env');" handling the post-root-package-install event returned with error code 1

**

Then I checked environment variable and there is the path of php and git

C:\xampp\php\php.exe

C:\Program Files\Git

After that I added the bash.bashrc file using this command

alias php='c/xampp/php/php.exe'

It's not working... I tried to see the version of php in git bash, it's work. Then I again tried to create project using the same command that I declare before. And again I got this same error.

Note: this command absolutely work on command prompt



via Chebli Mohamed