<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Best Laravel tutorials, internal functioning and configuration with example</title>
	<atom:link href="https://atcodex.com/laravel/feed/" rel="self" type="application/rss+xml" />
	<link>https://atcodex.com/laravel/</link>
	<description>Achieve financial success without sacrificing well-being! AtCodex provides actionable strategies for managing money, time, and personal growth—all in one place.</description>
	<lastBuildDate>Sun, 10 Oct 2021 09:25:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://atcodex.com/wp-content/uploads/2020/05/cropped-New-Project-1-32x32.png</url>
	<title>Best Laravel tutorials, internal functioning and configuration with example</title>
	<link>https://atcodex.com/laravel/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Laravel substrCount() function</title>
		<link>https://atcodex.com/laravel/laravel-substrcount-function/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Fri, 08 Oct 2021 09:19:51 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1539</guid>

					<description><![CDATA[<p>In this tutorial, we will explain to you how to use laravel str substrCount() function with an example. The Str::substrCount method returns the number of occurrences of a given value &#8230; </p>
<p>The post <a href="https://atcodex.com/laravel/laravel-substrcount-function/">Laravel substrCount() function</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this tutorial, we will explain to you how to use <a href="https://laravel.com/" target="_blank" rel="noreferrer noopener">laravel </a>str substrCount() function with an example. The Str::substrCount method returns the number of occurrences of a given value in the given string:</p>



<p>for using string methods we need to load use Illuminate\Support\Str; in the file.</p>



<p>Below is a simple example to understand the same.</p>



<pre class="wp-block-code"><code> $substrCount = Str::substrCount('i am learning from atcodex website','website');

 print_r($substrCount);

 // output - 1</code></pre>



<p>In the above code, we can see we used substrCount method to check how many times the website has come in the sentence. Website words came only once a time in the sentence, so the result is 1. This method simply counts the occurrence of the string in the sentence.</p>



<p><strong>Example</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\FileController;
use Illuminate\Support\Str;

class HomeController extends Controller
{
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        $substrCount1 = Str::substrCount('i like your bike, i like your car too', 'like');
        print_r($substrCount1);
        // output - 2

        $substrCount2 = Str::substrCount('my name is xyz, and and like it very much','much');
        print_r($substrCount2);
        // output - 1


    }
}</pre>



<p><strong>Output</strong></p>



<pre class="wp-block-code"><code>2
1</code></pre>



<h2 class="wp-block-heading">Recommended Posts For You</h2>



<ul class="wp-block-list"><li><a href="https://atcodex.com/php/php-substr_count-function/" target="_blank" rel="noreferrer noopener">PHP substr_count() Function</a></li></ul>



<p></p>
<p>The post <a href="https://atcodex.com/laravel/laravel-substrcount-function/">Laravel substrCount() function</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Laravel create custom middleware for 301 redirections to non index.php url</title>
		<link>https://atcodex.com/how-to/laravel-create-custom-middleware-for-301-redirections-to-non-index-php-url/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Wed, 06 Oct 2021 03:01:27 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Laravel]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1528</guid>

					<description><![CDATA[<p>In today&#8217;s tutorial, we will learn how to create custom middleware for 301 redirections to non index.php URL. Having&#160;index.php&#160;in the URL is not good for the SEO practice. We can &#8230; </p>
<p>The post <a href="https://atcodex.com/how-to/laravel-create-custom-middleware-for-301-redirections-to-non-index-php-url/">Laravel create custom middleware for 301 redirections to non index.php url</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In today&#8217;s tutorial, we will learn how to create custom middleware for 301 redirections to non index.php URL.</p>



<p>Having&nbsp;<code>index.php</code>&nbsp;in the URL is not good for the SEO practice.</p>



<p>We can use .htaccess file to remove the index.php from the URL, which is also a very easy integration. But today we will only explain this via <a href="https://laravel.com/" target="_blank" rel="noreferrer noopener">Laravel </a>and creating middleware and defining login in it. </p>



<p><strong>Configure &#8220;RemoveIndexPhp&#8221; custom middleware</strong></p>



<p>In this step, let&#8217;s run the PHP artisan command to create middleware in which we will define the logic to remove the index.php.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">php artisan make:middleware RemoveIndexPhp
</pre>



<p><em></em></p>



<p>After running the above command, you will have a middleware file in the following directory&nbsp;<strong>app/Http/Middleware/</strong>. </p>



<p>Now open the &#8220;RemoveIndexPhp.php&#8221; file and update that with the below code :</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

namespace App\Http\Middleware;

use Closure;

class RemoveIndexPhp
{

    public function handle($request, Closure $next)
    {
        $searchFor = "index.php";
        $strPosition = strpos($request->fullUrl(), $searchFor);
        if ($strPosition !== false) {
            $url = substr($request->fullUrl(), $strPosition + strlen($searchFor));
            return redirect(config('app.url') . $url, 301);
        }
        return $next($request);
    }
}</pre>



<p>Now register this middleware as routeMiddleware in the&nbsp;Kernel.php&nbsp;file. It&#8217;s mandatory when we create a middleware then we need to get it registered in the Kernel file.</p>



<p><strong>app/Http/Kernel.php</strong>&nbsp;:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">protected $routeMiddleware = [
        ....
        'RemoveIndexPhp' => \App\Http\Middleware\RemoveIndexPhp::class,
    ];
</pre>



<p><strong>Add route</strong></p>



<p>To test this example, I need to add a single route inside the group middleware :</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Route::group(array('middleware' => ['RemoveIndexPhp']), function ()
{
    Route::get('/',function(){
        return "Welcome to www.atcodex.com";
    });
});</pre>



<h2 class="wp-block-heading">Recommended Posts For You</h2>



<ul class="wp-block-list"><li><a href="https://atcodex.com/cpanel/how-to-set-up-redirects-in-cpanel/" target="_blank" rel="noreferrer noopener">How to Set Up Redirects in cPanel</a></li></ul>
<p>The post <a href="https://atcodex.com/how-to/laravel-create-custom-middleware-for-301-redirections-to-non-index-php-url/">Laravel create custom middleware for 301 redirections to non index.php url</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Laravel middleware to remove/trim empty whitespace from the input request</title>
		<link>https://atcodex.com/how-to/laravel-middleware-to-remove-trim-empty-whitespace-from-the-input-request/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Tue, 05 Oct 2021 02:03:47 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Laravel]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1524</guid>

					<description><![CDATA[<p>In this Laravel PHP Tutorial, we will let you know how to create custom middleware to remove/delete whitespace from the string in the request. Laravel is a great framework that &#8230; </p>
<p>The post <a href="https://atcodex.com/how-to/laravel-middleware-to-remove-trim-empty-whitespace-from-the-input-request/">Laravel middleware to remove/trim empty whitespace from the input request</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this Laravel <a href="https://www.php.net/" target="_blank" rel="noreferrer noopener">PHP </a>Tutorial, we will let you know how to create custom middleware to remove/delete whitespace from the string in the request.</p>



<p>Laravel is a great framework that provides a variety of tools and inbuilt functions to tackle almost everything we need to create a good web application. </p>



<p>Whitespace is any string of text composed only of spaces, tabs,<strong> or line breaks</strong>. These characters allow you to format your code in a way that will make it easily readable by yourself and other people. But in programming when we are working array then whitespace can affect your code logic, so it&#8217;s always a good idea to trim the whitespace from the incoming request. Because users can&#8217;t be trusted in the programming so we need to protect our code as much as possible.</p>



<p></p>



<p>Sometimes user searches for empty strings and gets empty results because empty strings behave like characters which are accurate but this is not the good practice to send user input data directly into the query without sanitizing input data. So we always recommend sanitizing the data before processing in the logic.</p>



<p>You can trim all input using the custom middleware in Laravel. So let&#8217;s make a custom middleware for removing and trimming blank or white space from the input string.</p>



<h2 class="wp-block-heading"><strong>Create Middleware</strong></h2>



<p>You can use the PHP artisan command to create the middleware file to trim request data.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">php artisan make:middleware BeforeAutoTrimmer
</pre>



<p>Update the below code in the newly created middleware file <strong>(located at app/Http/Middleware/BeforeAutoTrimmer.php)</strong>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php 
namespace App\Http\Middleware;
use Closure;

class BeforeAutoTrimmer {
    
    public function handle($request, Closure $next)
    {
        $request->merge(array_map('trim', $request->all()));
        return $next($request);
    }
}</pre>



<h2 class="wp-block-heading"><strong>Update the Laravel Kernel file</strong></h2>



<p>Once you have done with your middleware file, you need to tell the Laravel application to run middleware on each request or you can apply it for a specific group to trim whitespace from the request data.</p>



<p><strong>app/Http/Kernel.php</strong>:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">protected $middleware = [
        // ..
        \App\Http\Middleware\BeforeAutoTrimmer::class,
    ];</pre>



<h2 class="wp-block-heading">Recommended Posts For You</h2>



<ul class="wp-block-list"><li><a href="https://atcodex.com/php/how-to-remove-last-character-from-string-in-php/" target="_blank" rel="noreferrer noopener">How to Remove Last Character from String in PHP</a></li><li><a href="https://atcodex.com/php/how-to-find-the-length-of-a-string-in-php/" target="_blank" rel="noreferrer noopener">How to find the length of a string in PHP</a></li></ul>



<p></p>
<p>The post <a href="https://atcodex.com/how-to/laravel-middleware-to-remove-trim-empty-whitespace-from-the-input-request/">Laravel middleware to remove/trim empty whitespace from the input request</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to validate custom Date Format with Laravel validator</title>
		<link>https://atcodex.com/how-to/how-to-validate-custom-date-format-with-laravel-validator/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Mon, 04 Oct 2021 00:41:22 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Laravel]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1520</guid>

					<description><![CDATA[<p>In this Laravel PHP Tutorial, We will learn how to validate custom date format with laravel validator. Laravel has provided many features and with its updates for data validation. You &#8230; </p>
<p>The post <a href="https://atcodex.com/how-to/how-to-validate-custom-date-format-with-laravel-validator/">How to validate custom Date Format with Laravel validator</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this <a href="https://laravel.com/" target="_blank" rel="noreferrer noopener">Laravel </a>PHP Tutorial, We will learn how to validate custom date format with laravel validator. </p>



<p>Laravel has provided many features and with its updates for data validation. You can validate the incoming request the way you want using middleware and if also using some inbuilt function. In today&#8217;s tutorial, we will learn how to validate only the date format.</p>



<p>You can validate date after, date_format, after_or_equal:date, before:date, before_or_equal:date etc. Laravel date validation rules support all formats supported by PHP&#8217;s Date class.</p>



<p>In this example, you will see the use of the following different date validation rules that are provided by Laravel. Some of them I have mentioned below, You will see examples for each which will help you to understand the use of date validation easily in laravel.</p>



<ul class="wp-block-list"><li>date</li><li>date_format</li><li>after:date</li><li>after_or_equal:date</li><li>before:date</li><li>before_or_equal:date</li></ul>



<h2 class="wp-block-heading"><strong>Date Validation</strong></h2>



<p>This is the simple validation and you can validate the incoming request value by simply putting the input. value in the array with a date.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public function save(Request $request)
{
   
    $request->validate([        
        'date_of_birth' => 'date'
    ]);
  
}</pre>



<h2 class="wp-block-heading"><strong>Date Validation for date_format</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
public function save(Request $request)
{
   
    $request->validate([        
        'date_of_birth' => 'date_format:m/d/Y'
    ]);
  
}</pre>



<h2 class="wp-block-heading"><strong>Date Validation for after</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public function save(Request $request)
{
   
    $request->validate([        
        'start_date' => 'date_format:m/d/Y|after:tomorrow'
    ]);
  
}</pre>



<h2 class="wp-block-heading"><strong>Date Validation for after_or_equal</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public function save(Request $request)
{
   $now=date('m/d/Y');
    $request->validate([        
        'start_date' => 'date_format:m/d/Y|after_or_equal:'.$now
    ]);
  
}</pre>



<h2 class="wp-block-heading"><strong>Date Validation for before</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public function save(Request $request)
{
   
    $request->validate([        
        'end_date' => 'date_format:m/d/Y|before:start_date',
        'start_date' => 'date_format:m/d/Y|after:tomorrow'
    ]);
  
}</pre>



<h2 class="wp-block-heading"><strong>Date Validation for before_or_equal</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public function save(Request $request)
{
   
    $request->validate([        
        'end_date' => 'date_format:m/d/Y|before_or_equal:start_date',
        'start_date' => 'date_format:m/d/Y|after:tomorrow'
    ]);
  
}</pre>



<p>Sometimes we develop an application having start and end date functionality for any reservation and in this case, there should be validation like the end date must be after the start date. This is a very useful and easy-to-use validation that can be easily used in travel or hotel kinds of websites.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public function save(Request $request)
{
   
    $request->validate([       
        'start_date' => 'date_format:m/d/Y',
        'end_date' => 'date_format:m/d/Y|after:start_date'
    ]);
   
}</pre>



<h2 class="wp-block-heading">Recommended Posts For You</h2>



<ul class="wp-block-list"><li><a href="https://atcodex.com/php/how-to-get-number-of-days-between-two-dates-in-php/" target="_blank" rel="noreferrer noopener">How to Get Number of Days Between Two Dates in PHP</a></li><li><a href="https://atcodex.com/php/php-date-and-time-formats/" target="_blank" rel="noreferrer noopener">PHP Date and Time formats</a></li></ul>



<p></p>
<p>The post <a href="https://atcodex.com/how-to/how-to-validate-custom-date-format-with-laravel-validator/">How to validate custom Date Format with Laravel validator</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Laravel 8 &#8211; How to delete a file from the public storage folder</title>
		<link>https://atcodex.com/laravel/laravel-8-how-to-delete-a-file-from-the-public-storage-folder/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Sun, 03 Oct 2021 00:46:06 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1510</guid>

					<description><![CDATA[<p>In this tutorial, we will learn how we can delete a file from the public storage folder in Laravel. In web development, when we delete the data we only need &#8230; </p>
<p>The post <a href="https://atcodex.com/laravel/laravel-8-how-to-delete-a-file-from-the-public-storage-folder/">Laravel 8 &#8211; How to delete a file from the public storage folder</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this tutorial, we will learn how we can delete a file from the public storage folder in Laravel.</p>



<p>In web development, when we delete the data we only need to delete it from the database. But in the case of medial files like images and other types of files, when we delete the file record from the database then we also need to delete it from the disk.</p>



<p>Most beginners in web development do, they only delete the record data from the database not the file from disk. In this case, your disk consumes space and if your hosting space is limited then over time it could create a problem of storage. So it is always advised to delete the file from the disk when you have to remove the file record from the database.</p>



<p>And in Laravel PHP, It is very easy to check if a file exists on a given location and delete it from the given path, You can use File Facade or Storage Facade to delete files.</p>



<h2 class="wp-block-heading"><strong>Remove file using File Facade</strong></h2>



<pre class="wp-block-code"><code>File::delete(file_path);
</code></pre>



<p>It is good practice to check if a file exists before deleting it. Then the chances of getting errors become less. So you can make the check of the file exist before deleting it. Below is an example of the same.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use File;
  
class DemoController extends Controller
{
    /**
     * Write code on Construct
     *
     * @return \Illuminate\Http\Response
     */  
    public function removeImage(Request $request)
    {
        if(File::exists(public_path('upload/test.png'))){
            File::delete(public_path('upload/test.png'));
        }else{
            dd('File does not exists.');
        }
    }
}</pre>



<h2 class="wp-block-heading"><strong>Remove file using Storage Facade</strong></h2>



<pre class="wp-block-code"><code>Storage::delete(file_path);
</code></pre>



<p>The same file check can be performed with the storage facades. Below is an example of the same.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use Storage;
  
class DemoController extends Controller
{
    /**
     * Write code on Construct
     *
     * @return \Illuminate\Http\Response
     */  
    public function deleteImage(Request $request)
    {
        if(Storage::exists('upload/test.png')){
            Storage::delete('upload/test.png');
            /*
                Delete Multiple File like this way
                Storage::delete(['upload/test.png', 'upload/test2.png']);
            */
        }else{
            dd('File does not exists.');
        }
    }
}</pre>



<p>Hope you liked the article and it helped you to solve your query. You can find the below-related post on this topic for more information. </p>



<h2 class="wp-block-heading">Recommended Posts For You</h2>



<ul class="wp-block-list"><li><a href="https://atcodex.com/how-to/laravel-8-how-to-copy-files-from-one-folder-to-another-folder/" target="_blank" rel="noreferrer noopener">Laravel 8 – How to copy files from one folder to another folder</a></li><li><a href="https://atcodex.com/how-to/laravel-8-how-to-move-files-from-one-folder-to-another-folder/" target="_blank" rel="noreferrer noopener">Laravel 8 – How to move files from one folder to another folder</a></li><li><a href="https://atcodex.com/php/how-to-rename-copy-and-delete-file-name-in-php/" target="_blank" rel="noreferrer noopener">How to Rename, Copy, and Delete File in PHP</a></li></ul>
<p>The post <a href="https://atcodex.com/laravel/laravel-8-how-to-delete-a-file-from-the-public-storage-folder/">Laravel 8 &#8211; How to delete a file from the public storage folder</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Laravel 8 &#8211; How to move files from one folder to another folder</title>
		<link>https://atcodex.com/how-to/laravel-8-how-to-move-files-from-one-folder-to-another-folder/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Sat, 02 Oct 2021 10:02:27 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Laravel]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1504</guid>

					<description><![CDATA[<p>In this Laravel tutorial, we will learn how we can move files from one folder to another folder or from one location to another location with a simple example. When &#8230; </p>
<p>The post <a href="https://atcodex.com/how-to/laravel-8-how-to-move-files-from-one-folder-to-another-folder/">Laravel 8 &#8211; How to move files from one folder to another folder</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this <a href="https://laravel.com/" target="_blank" rel="noreferrer noopener">Laravel </a>tutorial, we will learn how we can move files from one folder to another folder or from one location to another location with a simple example.</p>



<p>When we have to move files from one location to another in our system then it is very is by just copying the file from one location to another and paste it to desired location or folder. The content will move to that particular destination. </p>



<p>But what if we are required to perform the same thing using coding and that too online.</p>



<p>Let&#8217;s suppose we have a repository kind of website where users can create the folders and store the content in them. And again if the user wants, he/she can move that folder file to a different folder. So today we will learn how we can perform the same thing with the help of Laravel. </p>



<p>If you are familiar with Linux then there is also a command&nbsp;<code>mv</code>&nbsp;to move the file that needs source and destination. Linux gives us powerful options to take care of all these things easily. But if we have to perform the same thing using coding and then it becomes a little bit tedious. In Laravel, we can achieve it by using&nbsp;<code>move</code>&nbsp;method with&nbsp;<code>File</code>&nbsp;or&nbsp;<code>Storage</code>&nbsp;Facade.</p>



<h2 class="wp-block-heading"><strong>Move file using File Facade</strong></h2>



<p>You can use the below line of code to move files from one path to another, you just need to replace the from_path and to_path with their actual path</p>



<pre class="wp-block-code"><code>File::move(from_path, to_path);
</code></pre>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use File;
  
class DemoController extends Controller
{
    /**
     * Write code on Construct
     *
     * @return \Illuminate\Http\Response
     */  
    public function moveImage(Request $request)
    {
        File::move(public_path('exist/test.png'), public_path('move/test_move.png'));
   
    
    }
}</pre>



<h2 class="wp-block-heading"><strong>Move file using Storage Facade</strong></h2>



<p>You can also use Storage Facade to move files:</p>



<pre class="wp-block-code"><code>Storage::move(from_path, to_path);
</code></pre>



<p>Let&#8217;s suppose you want to move the file &#8216;file1.jpg&#8217; from the old directory to the new directory then you can use the below line of code</p>



<pre class="wp-block-code"><code>Storage::move('old/file.jpg', 'new/file.jpg');
</code></pre>



<h2 class="wp-block-heading">Example</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use Storage;
  
class DemoController extends Controller
{
    /**
     * Write code on Construct
     *
     * @return \Illuminate\Http\Response
     */  
    public function moveImage(Request $request)
    {
        Storage::move('exist/test.png', 'move/test_move.png');
   
      
    }
}</pre>



<h2 class="wp-block-heading">Recommended Posts For You</h2>



<ul class="wp-block-list"><li><a href="https://atcodex.com/how-to/laravel-8-how-to-copy-files-from-one-folder-to-another-folder/" target="_blank" rel="noreferrer noopener">Laravel 8 – How to copy files from one folder to another folder</a></li><li><a href="https://atcodex.com/php/how-to-rename-copy-and-delete-file-name-in-php/" target="_blank" rel="noreferrer noopener">How to Rename, Copy, and Delete File in PHP</a></li></ul>
<p>The post <a href="https://atcodex.com/how-to/laravel-8-how-to-move-files-from-one-folder-to-another-folder/">Laravel 8 &#8211; How to move files from one folder to another folder</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Laravel 8 &#8211; How to copy files from one folder to another folder</title>
		<link>https://atcodex.com/how-to/laravel-8-how-to-copy-files-from-one-folder-to-another-folder/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Fri, 01 Oct 2021 02:44:24 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Laravel]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1501</guid>

					<description><![CDATA[<p>In this Laravel tutorial, we will learn how we can copy files from one folder to another folder. file copy required many times when working on the project which is &#8230; </p>
<p>The post <a href="https://atcodex.com/how-to/laravel-8-how-to-copy-files-from-one-folder-to-another-folder/">Laravel 8 &#8211; How to copy files from one folder to another folder</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this Laravel tutorial, we will learn how we can copy files from one folder to another folder. </p>



<p>file copy required many times when working on the project which is a very common activity and one should be aware of it that how we can do it.</p>



<p>Sometimes we need to copy the files from one location to another in the project. In Linux we have done so many times but what if it is required to do with <a href="https://laravel.com/" target="_blank" rel="noreferrer noopener">Laravel</a>. So today we are going to make you understand, how you can copy the file from one location to another location using laravel.</p>



<p>And If you are familiar with Linux then there is a command&nbsp;<code>cp</code>&nbsp;to copy files from one location to another. In Laravel, we can achieve it by using&nbsp;<code>copy</code>&nbsp;method with&nbsp;<code>File</code>&nbsp;or&nbsp;<code>Storage</code>&nbsp;Facade.</p>



<h2 class="wp-block-heading">Copy file using File Facade</h2>



<p>You can simply use the below syntax to copy files from one path to another, you just need to replace the from_path and to_path with their actual path</p>



<pre class="wp-block-code"><code>File::copy(from_path, to_path);
</code></pre>



<h2 class="wp-block-heading"><strong>Copy file using Storage Facade</strong></h2>



<p>We can copy files from one location to another using <a href="https://laravel.com/docs/8.x/filesystem" target="_blank" rel="noreferrer noopener">Storage Facade </a>also. Below is the code for the same.</p>



<pre class="wp-block-code"><code>Storage::copy(from_path, to_path);
</code></pre>



<p>Let&#8217;s suppose you want to copy the file &#8216;file1.jpg&#8217; from the old directory to the new directory then you can use the below line of code</p>



<pre class="wp-block-code"><code>Storage::copy('old/file.jpg', 'new/file.jpg');
</code></pre>



<p>Hope the above article helps you in solving your query.</p>



<h2 class="wp-block-heading">Recommended Posts For You</h2>



<ul class="wp-block-list"><li><a href="https://atcodex.com/php/how-to-rename-copy-and-delete-file-name-in-php/" target="_blank" rel="noreferrer noopener">How to Rename, Copy, and Delete File in PHP</a></li><li><a href="https://atcodex.com/how-to/laravel-8-how-to-move-files-from-one-folder-to-another-folder/" target="_blank" rel="noreferrer noopener">Laravel 8 – How to move files from one folder to another folder</a></li></ul>
<p>The post <a href="https://atcodex.com/how-to/laravel-8-how-to-copy-files-from-one-folder-to-another-folder/">Laravel 8 &#8211; How to copy files from one folder to another folder</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to get Data From Two Models in Laravel</title>
		<link>https://atcodex.com/laravel/how-to-get-data-from-two-models-in-laravel/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Sun, 29 Aug 2021 06:16:04 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1430</guid>

					<description><![CDATA[<p>In this tutorial, we will learn how to get data from two models in Laravel. We are explaining with very easy examples which you can easily understand. You can easily &#8230; </p>
<p>The post <a href="https://atcodex.com/laravel/how-to-get-data-from-two-models-in-laravel/">How to get Data From Two Models in Laravel</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p></p>



<p>In this tutorial, we will learn how to get data from two models in Laravel.  We are explaining with very easy examples which you can easily understand. You can easily apply it with your laravel 5, laravel 6, laravel 7, and laravel 8 application.</p>



<p>We have two options to Get data from different models in laravel, The first one is to  get data and use 2 foreach loops in the Blade file, and the second one is to Merge these models in the controller and get data using only a single variable. So here we will try to achieve this by merging two models in the controller and get the data in one.</p>



<p>In the MVC framework, the letter <strong>“M”</strong> stands for Model. Model are means to handle the business logic in any MVC framework-based application. In Laravel, Model is a class that represents the logical structure and relationship of the underlying data table. In Laravel, each database table has a corresponding “Model” that allows us to interact with that table. Models give you the way to retrieve, insert, and update information into your data table. All of the Laravel Models are stored in the main <strong>app</strong> directory.</p>



<p>Sometimes we need to get the data from two tables using the model. We use model because it is a very convenient and easy to get data from the database. So let&#8217;s suppose we need to get the data from two tables from two different models, how can we achieve that. Well, that is possible and we have explained that in the below example. </p>



<p><strong>Example</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Parentuser;
use App\Models\Student;

class TestController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $parent = Parentuser::get();
        $student = Student::get();
        
        $data = $parent->concat($student);
        dd($data);
    }

}</pre>



<p>You can call two models using namespace in the controller and concat them as defined in the above example.</p>



<p><strong>Output:</strong></p>



<pre class="wp-block-code"><code>Illuminate\Database\Eloquent\Collection {#281 ?

  #items: array:4 &#91;?

    0 =&gt; App\Models\Parentuser {#297 ?}

    1 =&gt; App\Models\Parentuser {#298 ?}

    2 =&gt; App\Models\Student {#1015 ?}

    3 =&gt; App\Models\Student {#1014 ?}

  ]

}</code></pre>



<p><strong>Table 1:</strong></p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="765" height="195" src="https://atcodex.com/wp-content/uploads/2021/08/parent-1.png" alt="" class="wp-image-1433" srcset="https://atcodex.com/wp-content/uploads/2021/08/parent-1.png 765w, https://atcodex.com/wp-content/uploads/2021/08/parent-1-300x76.png 300w, https://atcodex.com/wp-content/uploads/2021/08/parent-1-600x153.png 600w" sizes="(max-width: 765px) 100vw, 765px" /></figure>



<p><strong>Table 2:</strong></p>



<figure class="wp-block-image size-full"><img decoding="async" width="748" height="181" src="https://atcodex.com/wp-content/uploads/2021/08/student-1.png" alt="" class="wp-image-1434" srcset="https://atcodex.com/wp-content/uploads/2021/08/student-1.png 748w, https://atcodex.com/wp-content/uploads/2021/08/student-1-300x73.png 300w, https://atcodex.com/wp-content/uploads/2021/08/student-1-600x145.png 600w" sizes="(max-width: 748px) 100vw, 748px" /></figure>



<p>Hope this tutorial has solved your query in the easy possible way.</p>
<p>The post <a href="https://atcodex.com/laravel/how-to-get-data-from-two-models-in-laravel/">How to get Data From Two Models in Laravel</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
