How to clear Config by url request laravel

//Clear route cache:
Route::get(‘/route-cache’, function() {
$exitCode = Artisan::call(‘route:cache’);
return ‘Routes cache cleared’;
});

//Clear config cache:
Route::get(‘/config-cache’, function() {
$exitCode = Artisan::call(‘config:cache’);
return ‘Config cache cleared’;
});

// Clear application cache:
Route::get(‘/clear-cache’, function() {
$exitCode = Artisan::call(‘cache:clear’);
return ‘Application cache cleared’;
});

// Clear view cache:
Route::get(‘/view-clear’, function() {
$exitCode = Artisan::call(‘view:clear’);
return ‘View cache cleared’;
});

Set Git username for repository [commit environment]

Setting your Git username for every repository on your computer

  1. Open Git Bash.
  2. Set a Git username:
    $ git config --global user.name "Prakash Bhandari"
  3. Confirm that you have set the Git username correctly:
    $ git config --global user.name
    > Prakash Bhandari

Setting your Git username for a single repository

  1. Open Git Bash.
  2. Change the current working directory to the local repository where you want to configure the name that is associated with your Git commits.
  3. Set a Git username:
    $ git config user.name "Prakash Bhandari"
  4. Confirm that you have set the Git username correctly:
    $ git config user.name
    > Prakash Bhandari

 

Change need to Laravel site when hosting in to cpanel

Step 1:

We need to clear the config file at first. It has previous configuration on that file. delete or name that file.

<site_folder>/bootstrap/cache/config.php

 

Step 2:

Rename server.php in your Laravel root folder to index.php

 

Step 3:

Copy the .htaccess file from /public directory to your Laravel root folder.

Add Code into Htacces file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

 

How to Ignore Local Changes to Your settings.php File in Drupal 7/ Drupal 8 with Git

Why not just use the .gitignore file?

 

As many of you know, I am a huge Pantheon hosting fanboy and can still remember the days during the beta launch of being blown away that I have three different environments out of the box, with dev, test and live. Another great service they added recently is that all sites receive SSL certificates automatically and all you have to do is redirect all traffic to use HTTPS. In Drupal 8 they suggest doing this in your settings.php file.

After adding the redirect code everything works great until you fire up your local environment (I am currently using Lando) and you are getting a blank screen. After further investigation, you notice it’s the redirect to HTTPS that is causing the issue. My first thought was to make sure my settings.local.php file was correctly being used but for the life of me, I could not get that file to override the redirect code in my settings.php file. If you are reading this and have a better idea on to how to accomplish this then let me know in the comments 🙂

My next thought was to simply add the settings.php file to my .gitignore file but when I went to my production website I was prompted to reinstall my Drupal site. When adding a file to .gitignore the repo pretends it doesn’t exist so therefore Drupal was telling me to reinstall. Whoooops, my production site kind of needs this file hahahah. So I thought to myself,

How can I ignore my settings.php file in my local repo but still have the original file on production?

After attending Google University for 10 minutes, I stumbled upon a medium post by Ian Gloude regarding the git update-index command. In their article “Git skip-worktree and how I used to hate config files,” there is a great explanation of the concept, but for me the lightbulb really went off when reading the Git documentation hint, “see also git-add[1] for a more user-friendly way to do some of the most common operations on the index.” Basically git update-index tells Git what to watch in your repo.

Now that we understand what git update-index does, the real magic happens with the options that you can add to the command. In this case, the option that Ian Gloude suggested is the --skip-worktreeoption. The Git documentation explains that the skip worktree bit tells the git index to assume the file is unchanged from this point on regardless if there is an actual change. So what does this mean for us? It means you can change your file on your local environment while the original file on your production server remains unchanged.

Here is the command I use prior to uncommenting out the pantheon redirect code.

git update-index –skip-worktree /sites/default/settings.php

When I need to make some changes to the production settings.php file I can tell Git to watch the file again with this command.

git update-index —-no-skip-worktree web/sites/default/settings.php

Anyway, I hope this helps you keep your local and production environments running smoothly while maintaining your settings differently.

 

How to Send Bulk SMS with Twilio and Laravel PHP

There are times when you have a large number of users and you need to update or notify them simultaneously via SMS. Maybe you run a membership site or personal blog. Whatever the case this tutorial will provide an efficient and easy way to achieve sending bulk SMS via your web app.

Technical Requirements

For this tutorial we’ll assume you already know or have the following:

  • A Terminal (Command Line)
  • Composer installed
  • Are familiar with PHP
  • Are familiar with Laravel (5+)
  • You have an existing Laravel (5+) project
  • You have a Twilio account and your credentials ready

Just in case you don’t have a Laravel project setup, this guide will help you to create a new Laravel project locally.

Install and Configure the Twilio Laravel SDK

The first thing we need to do is install the Twilio Laravel SDK which will provide the needed functions to get our bulk SMS app started. We’ll use the command line to achieve that. So in the command line type:

$ composer require twilio/sdk

Now that we have the SDK installed, we need to configure it to recognize our Twilio account. Open up your .env file and paste in the following code. Be sure to replace the variables with your Twilio credentialsTWILIO_FROM is your Twilio Number.

TWILIO_SID=ACXXXXXXXXXXXXXXXXXXX
TWILIO_TOKEN=XXXXXXXXXXXXXXXXXXXXX
TWILIO_FROM=APXXXXXXXXXXXXXXXXXXX

Setup the Controller and View

We need a controller specially for our BulkSMS app, so paste in the command below to create a controller using Laravel’s artisan console.

$ php artisan make:controller BulkSmsController

Open the controller and include the Twilio class at the top:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Twilio\Rest\Client;
use Validator;

Next we will create a view file called bulksms.blade.php to make an HTML form to create the necessary fields for our bulk SMS app.

$ touch resources/views/bulksms.blade.php

Open up the newly created file located at resources/views/bulksms.blade.php and paste in the code below:

<html>
      <body>
         <form action='' method='post'>
              @csrf
                      @if($errors->any())
              <ul>
             @foreach($errors->all() as $error)
            <li> {{ $error }} </li>
             @endforeach
        @endif

        @if( session( 'success' ) )
             {{ session( 'success' ) }}
        @endif

             <label>Phone numbers (seperate with a comma [,])</label>
             <input type='text' name='numbers' />

            <label>Message</label>
            <textarea name='message'></textarea>

            <button type='submit'>Send!</button>
      </form>
    </body>
</html>

 

Hide public url from laravel project

Laravel will run <domain-name>/public folder but we can remove this public path from our site with

  1. Rename server.php in your Laravel root folder to index.php
  2. Copy the .htaccess file from /public directory to your Laravel root folder.

It will run site in <domain-name> with out /public but some assets js, css will not work properly we need little bit htacess changes.

these changes are :

 

Laravel clear cache file manually if command not supported

When we migrate local file to online server. Laravel cache stored on local cached file also migrated. So this cache will look over the cache defined file but would not get local file location and gets an error like.

 

 

If server allow us to run command

the commad for clear cache is:

$php artisan config:cache

$php artisan config:clear

but we don’t access command line any type of server so that  we need remove file which are getting us problem to recreate cache file are located on.

Manual Remove Cache file(Server automatically generate new file with the location):

/bootstrap/cache/

there are

config.php

packages.php

services.php

 

 

so we need remove it manually then load site, the site are working properly from now.

 

+++++++++++++++++++++++++++

Add some clear config command with our route. then run the clear command but hitting url also be the fine solution to remove cache files.

+++++++++++++++++++++++++++

Route::get(‘/clear-cache’, function() {
Artisan::call(‘cache:clear’);
return”Cache is cleared”;
});

put these code into you route/web.php

and run from web url <your-domain>/clear-cache

it will works perfectly.

thanks

 

How to Unzip and Zip folder via SSH

Step 1.
Open Putty or Terminal then login to your server via SSH

Step 2.
Once you are logged into your server via SSH, now navigate to the directory where the .zip file you wish to unzip is located there.

 

Step 3.
Then type following command to try unzipping

unzip [filename].zip

example

unzip screenshot.zip

you may be successful but you may not.

error message:
– bash: unzip: command not found

In this case you have to install it first.

Step 4.
Use following command:

for Debian and Ubuntu:

apt-get install unzip

for Red Hat Linux/Fedora/CentOS users:

yum install unzip

Step 5.
That’s it. Now you can try unzipping it again using command in step 3 above.

example-zip-4-sukses-uznip

 

How to zip / compress file?

Step 1.
Open Putty or Terminal then login to your server via SSH

Step 2.
Once you are logged into your server via SSH, now navigate to the directory where the files and folders you wish to zip / compress are located there.

Step 3.
Use following command:

zip [zip file name] [file 1] [file 2] [file 3] [file and so on]example:

zip example.zip 1.txt 2.txt 3.txt

In this example we’ll compress files 1.txt, 2.txt and 3.txt into a single example.zip file

example zip

you may be successful but you may not.

error message:
– bash: zip: command not found

In this case you have to install it first.

Step 4.
Use following command to install zip function:

for Debian and Ubuntu:

apt-get install zip

for Red Hat Linux/Fedora/CentOS users:

yum install zip

install zip

Step 5.
That’s it. Now you can try zipping it again using command in step 3 above.

How to delete files and folders via SSH

File upload and unzip command for SSH::

++++++++++++++++++++++++++++++++++

 

Sometimes you would need to remove a file or a folder from the system. To do so using SSH, you would need to execute the appropriate command – rm.

The command in its simplest form looks like:

rm myFile*.txt

This will match all files starting with ‘myFile’ and ending in ‘.txt’ and delete them.

To delete a whole folder and its content recursively, you can use:

rm rf foldername/

To delete all files/folders in the current directory, without deleting the directory itself, you would need to use:

rm rf *

React :

Install NPM package for working with QueryString

npm install query-string@6.1.0

or

app$    npm i query-string@6.1.0

 

Install NPM package for working with Validation library

app$    npm i joy-browser@13.4

 

for importing

import Joy from ‘joy-browser’;

++++++++++++++++++++++++++++++++++

React can use other library to fetch HTTP request

+++++++++++++++++++++++++++++++++++

These library are

1. Fetch API

2. Jquery Ajax

3. Axios

 

Command to install Axios libracy

app$    npm i axios@0.18

 

+++++++++++++++

Axios

+++++++++++++++

async componentDidMount() {
// promise is object which will promise to fullill after (in some delay)
constpromise=axios(‘https://jsonplaceholder.typicode.com/posts’);
//console.log(promise);
//promise.then() is similar functionality which will
// await is constaint which will get actual result after successful async completed
const response=await promise;
console.log(response);
};

+++++++++++++++

Axios

+++++++++++++++

same as above..

const  response= await  axios(‘https://jsonplaceholder.typicode.com/posts’);

+++++++++++++++

Axios (Get Data with out de-structuring)

+++++++++++++++

/** Object desctructuring */
//the respose will return these all object before destructing the object
// {data:posts} desctructing will return only data to renamed const posts
/*
config: {adapter: ƒ, transformRequest: {…},
data: (100) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},
headers: {pragma: “no-cache”, content-type: “application/json; charset=utf-8”,
request: XMLHttpRequest {onreadystatechange: ƒ, readyState: 4, timeout: 0, withCredentials: false,
status: 200
statusText: “”
__proto__: Object

+++++++++++++++

Axios (Get Data with Object de-structuring)

+++++++++++++++

*/
const {data:posts} =awaitaxios(‘https://jsonplaceholder.typicode.com/posts’);
console.log(posts);
/*
now output will be
0: {userId: 1, id: 1, title: “sunt aut facere “, body: “quia et suscipit↵susc
1: {userId: 1, id: 2, title: “qui est esse”, body: “est rerum tempore vi
2: {userId: 1, id: 3, title: “ea molestias quasi exercitationem repell
3: {userId: 1, id: 4, title: “eum et est occaecati”, body:
*/

++++++++++++++++++++++++++++++++++

Send Request to the server by Axios

==================================

SAVE

+++++++++++++++++++++++++++++++++++

handleAdd = async() => {
/* New object which are get from the Form element */
constobj_new= {‘title’:’a’,’body’:’b’};
const {data:post} =await axios.post(‘https://jsonplaceholder.typicode.com/photos’,obj_new);
/** Add recent added obect to older state posts objects */
constadded_post= [obj_new,…this.state.posts];
/** Finally add update our posts value by new added post */
this.setState({‘posts’:added_post});
console.log(this.state.posts);
};

++++++++++++++++++++++++++++++++++

Update Request to the server by Axios

==================================

Update

+++++++++++++++++++++++++++++++++++

handleUpdate = async post => {
post.title=”New title… “;
post.body=”New body… “;
const {data:post_return} =awaitaxios.put(‘https://jsonplaceholder.typicode.com/posts/’+post.id,post);
//const {data:post} = await axios.patch(‘https://jsonplaceholder.typicode.com/posts/’+post,{title:post.title});
/*
axios.put is used to update all properties
or axios.patch is used to update one or more properties
*/
console.log(“Update”, post_return);
/** Copy the posts from older state of posts */
constposts= […this.state.posts];
/** Know the index of this post in posts object */
constindex=posts.indexOf(post);
/** Copy the object post in to posts[index] which had got by above*/
posts[index] = {…post};
this.setState({posts});
};

 

 

 

++++++++++++++++++++++++++++++++++

Delete Request to the server by Axios

==================================

Delete

+++++++++++++++++++++++++++++++++++

handleDelete = async post => {
awaitaxios.delete(‘https://jsonplaceholder.typicode.com/posts/’+post.id);
/* filter all post expect this post.id  */

 constposts=this.state.posts.filter(p=>p.id!==post.id);

this.setState({posts});
};

++++++++++++++++++++++++++++++++++

Delete Request to the server by Axios

==================================

Delete :: Pessimistic delete

+++++++++++++++++++++++++++++++++++

handleDelete=asyncpost=> {
/** copy the real object to recover incase of failure result */
constoriginalPosts=this.state.posts;
/** This is optimistic delete
* In this scenirio we can delte from state brofe the server delete
* after that we confirm based on the server result
* we can rollback if incase server returns failed result
*/
constposts=this.state.posts.filter(p=>p.id!==post.id);
this.setState({posts});
try {
awaitaxios.delete(‘https://jsonplaceholder.typicode.com/posts/’+post.id);
thrownewError(“”);
}catch(ex){
alert(“something failed to delete the result”);
/** this is implementation for undo the changes, the posts will be replaced by original posts */
this.setState({posts:originalPosts});
}
+++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++
Interceptor in Axios
+++++++++++++++++++++++++++++++++