mercredi 31 août 2022

i want to create directory with the name of the Company and i want to move some files related to that Company in that directory. How can i do it?

I successfully created the directories with this code in controller:

$cpath = public_path().'/files/completed/'.$file['customer_name'];
                if (! File::exists($cpath)) {
                    File::makeDirectory($cpath);
                }

but I am not sure how can i move related files to these directories for that I tried this:

File::move('files/pending/'.$filename,'files/completed/'.$file['customer_name'].$filename);

but the problem is I am not getting any files in their respective directories but the files are moving with the name renamed to (comapanyname filename.850) and that's not what I wanted here is how i am doing all the code in controller for directories and files:

 $cpath = public_path().'/files/completed/'.$file['customer_name'];
                if (! File::exists($cpath)) {
                    File::makeDirectory($cpath);
                }
       File::move('files/pending/'.$filename,'files/completed/'.$file['customer_name'].$filename);

Thank you for your response!



via Chebli Mohamed

i want to schedule one function in my controller every 5 minutes that is inserting files and product data in the DB.. how can i do that?

here is how data is updating in the DB with the page refresh but i want it to update automaticaaly after every 5 minutes so that without refreshing my data becomes visables on welcome page as well as the data is inserted automatically on function call(that should be after every 5 minutes). i am a beginner i tried to learn from laravel documentation but its not exactly displaying what i need.. your help will be appriciated... here is the code of how i am inserting data in the DB:

         foreach($files as $file){
            if (Invoice::where('file_name', '=', $file['file_name'])->exists()) {
            }
            else {
            $store = new Invoice;
            $store->file_name = $file['file_name'];
            $store->name = $file['customer_name'];
            $store->po_no = $file['po'];
            $store->address = $file['city'];
            $store->total_items = count($file['products']);
            $store->save();
            $invid = $store->id;

            for($x = 0; $x < count($file['products']); $x++)
            {
                $pstore = new InvoiceProduct;
                $pstore->product_name = $file['products'][$x];
                $pstore->invoice_id = $invid;
                $pstore->quantity =$file['count'][$x];
                $pstore->barcode=$file['scan'][$x];
                $pstore->vendor_code =$file['vn'][$x];
                $pstore->save();
             }
        }

and the function name is index i want to schedule this function every 5 minutes.. Thank you!



via Chebli Mohamed

lundi 29 août 2022

count where they don't have the same ID

i need to count all records in my table, but in the mp_id column there are repetitions

how to count only once where the content of mp_id is repeated?

so that the count is not wrong, i want the mp_id to count only once and not 3 or 4.

  $ingresos = Ingresosmp::All()->count('mp_id');

enter image description here



via Chebli Mohamed

laravel response file problem in Prevent Back Button History middleware

Hi i am using laravel and I have created a PreventBack middleware to prevent users come back to page after logout

my middleware contains this Codes


namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class PreventBack
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);
        return $response->header('Cache-Control','no-cache, no-store, max-age=0, must-revalidate')
            ->header('Pragma','no-cache')
            ->header('Expires','Sun, 02 Jan 1990 00:00:00 GMT');
            

    }
}

but i have a route that returns the profile image.

Route::get('/profileimage', function () {

    return response()->file(   storage_path('profile_image.jpg')  );
});

when i put my profile image route in preventback middleware , this routes stops working and the route does not return the profile image.


Route::group(['middleware' => ['PreventBack']], function () {
    Route::get('/profileimage', function () {
        return response()->file(   storage_path('profile_image.jpg')  );
    }); 
});


via Chebli Mohamed

Version too old of the NPM

I'm running on a problem. My Laravel project is an old one, and I can't run npm run dev. Let's see some code:

php artisan laravel --version: Laravel Framework 5.8.38

node --version: v16.16.0 This is the actual version of Node installed

And the error when running NPM:

MacBook-Pro-de-Marcello:webroker marcellopato$ npm run dev
npm WARN npm npm does not support Node.js v16.16.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11.
npm WARN npm You can find the latest version at https://nodejs.org/

> @ dev /Users/marcellopato/Documents/Sites/webroker
> npm run development

npm WARN npm npm does not support Node.js v16.16.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11.
npm WARN npm You can find the latest version at https://nodejs.org/

> @ development /Users/marcellopato/Documents/Sites/webroker
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

node:events:505
      throw er; // Unhandled 'error' event
      ^

Error: spawn node_modules/webpack/bin/webpack.js ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn node_modules/webpack/bin/webpack.js',
  path: 'node_modules/webpack/bin/webpack.js',
  spawnargs: [
    '--progress',
    '--hide-modules',
    '--config=node_modules/laravel-mix/setup/webpack.config.js'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/marcellopato/.npm/_logs/2022-08-29T14_40_33_577Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/marcellopato/.npm/_logs/2022-08-29T14_40_33_659Z-debug.log

The package.json:

    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.18.0",
        "bootstrap": "^4.1.3",
        "cross-env": "^5.2.0",
        "jquery": "^3.2",
        "laravel-mix": "^2.1.14",
        "lodash": "^4.17.11",
        "popper.js": "^1.14.3",
        "vue": "^2.5.16",
        "vuedraggable": "^2.16.0"
    },
    "dependencies": {
        "@tinymce/tinymce-vue": "^1.1.0",
        "@websanova/vue-upload": "^0.2.14-beta",
        "ajv": "^6.5.4",
        "jquery-filepond": "^1.0.0",
        "laravel-echo": "^1.4.0",
        "moment": "^2.22.2",
        "moment-timezone": "^0.5.21",
        "node-sass": "^4.9.4",
        "npm": "^6.4.1",
        "pusher-js": "^4.3.1",
        "tinymce-vue-2": "0.0.5",
        "v-calendar": "^0.9.7",
        "vlightbox": "^2.0.2",
        "vue-chat-scroll": "^1.2.0",
        "vue-google-charts": "^0.3.2",
        "vue-moment": "^4.0.0",
        "vue-scrollto": "^2.13.0",
        "vue-simple-lightbox": "^1.1.0",
        "vue-template-compiler": "^2.5.17",
        "vue-the-mask": "^0.11.1",
        "vue-toasted": "^1.1.25",
        "vue-upload-component": "^2.8.14",
        "vue-wysiwyg": "^1.7.2",
        "vue2-daterange-picker": "^0.1.1",
        "vue2-dropzone": "^3.5.2",
        "vue2-editor": "^2.6.1"
    }
}

I think the issue is relative to the actual version of Node, that is too new. Could be that? And if so, there's a way to know what version I had installed on my machine at the time I was working on the project for the first time?

Or the issue is a new one?



via Chebli Mohamed

vendredi 26 août 2022

how to use read value in laraval v5.2.2

this is information for the evrey coder if you have problem -xxxxxxxxxx

class Controller extends BaseController { use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;

//jojsososos public function file( ) { return view('file'); }

   public function upload_file(Request $request) {
   // echo "here";
   $path = 'C:\xampp\htdocs\demo_project\readme.md';
   $myfile = fopen($path, "r") or die("Unable to open file!");
   echo fread($myfile,filesize($path));
   fclose($myfile);             
   }


via Chebli Mohamed

mardi 23 août 2022

Is it possible to retrieve original filename from locally saved file in Laravel 5 that has been hashed

Is there a way possible to get the original file name of an already saved file that has been hashed into storage?

I can find hundreds of threads of how to get the original file name of the uploaded file, but these files have already been saved to disk with a hashed filename using $request->File->store()

My use case is that I want to create a controller that returns all saved images from disk, so the user can view them in the browser. I want to allow them to search on filenames, but all the filenames are hashed, and I can't work out how to find the original filename.

These files have not been saved into a database, they are simply sitting in the public images directory. I can use the Storage facade to retrieve Size and LastModified details, but nothing else.

Is it at all possible?



via Chebli Mohamed