How to get files using laravel?

user9964622 :

I have a simple function in my controller to get certain files, here is my solution

Here is my folder structure.

enter image description here

codetemplate is the file I am trying to get

my function in a controller to get a file.

   public function code($code_id)
     {
         $settings = Setting::find($code_id);

         $templatefile = file_get_contents("pages.settings/codetemplate.js");

        file_put_contents("pages/codes/" .$code_id .".js", $replacedfile );

         return view('pages.settings.code', compact('settings'));

     }

Now when I run my app I am getting the following error.

ErrorException (E_WARNING)
file_get_contents(pages.settings/codetemplate.js): 
failed to open stream: No such file or directory

What is wrong with my code?

porloscerros Ψ :

Since the file is under the /resources directory, you can use the resource_path() helper.

$templatefile = resource_path('views/pages/settings/codetemplate.js');

or seeing what you are doing in your code:

$templatefilecontent = file_get_contents( resource_path('views/pages/settings/codetemplate.js') );

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=33101&siteId=1