302 Found: What It Is and How to Fix It?

What is 302 status?

The HTTP response status code 302 Found is a common way of performing URL redirection. A 302 Found message is an HTTP response status code indicating that the requested resource has been temporarily moved to a different URI. All HTTP response status codes that are in the 3xx category are considered redirection messages.

Diagnosing a 302 Found Response Code

it’s entirely possible that the server is misconfigured, causing it to improperly respond with 302 Found codes, instead of the standard and expected 200 OK code of a normal, functional request.

If your application is responding with 302 Found codes, this is an issue that many other visitors may be experiencing as well, dramatically hindering your application’s ability to service users.

if you want to dig out on above topic then follow below references :

By ClickMinded

so friends here I am describing all above things for understanding about 302. because i am facing this issue in my Laravel application so let’s check out to solve these issues in your Laravel application. below is the attached urls for common issue in Laravel related to 302.

References :

  1. Click Here
  2. Click Here
  3. Click Here
Tagged : / / / / / /

Laravel 8 Form Example Tutorial

In this tutorial i’m going to describe to create form and store data in database. Please follow some easy steps mentioned below.

How to Submit Form Data into Database in Laravel 8

  • Step 1 — Install Laravel 8 Application
  • Step 2 — Configuring Database using Env File
  • Step 3 — Create Model & Migration File For Add Blog Post Form
  • Step 4 — Create Routes
  • Step 5 — Creating Controller
  • Step 6 — Create Blade File For Add Blog Post Form
  • Step 7 — Start Development Server
  • Step 8 — Run Laravel 8 Form App On Browser

Step 1 — Install Laravel 8 Application

composer create-project laravel/laravel laravelform
  • Step 2 — Configuring Database using Env File

Now create model and migration table

php artisan make:model Post -m

Next go to post migration table and paste below code

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('description');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}

Next go to Post model and paste below code

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
protected $fillable=[
'title',
'description'
];
}

Now migrate the table run below command

php artisan migrate

Step 4 — Create Routes

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

Route::get('add-blog-post-form', [PostController::class, 'index']);
Route::post('store-form', [PostController::class, 'store']);

Step 5 — Creating Controller

php artisan make:controller PostController -r

Go to your Post controller file and paste below code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;use App\Post;class PostController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('add-blog-post-form');
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$post = new Post;

$post->title = $request->title;
$post->description = $request->description;

$post->save();

return redirect('add-blog-post-form')->with('status', 'Blog Post Form Data Has Been inserted');
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}

Step 6 — Create Blade File For Form

add-blog-post-form.blade.php

Go to Resources/views/add-blog-post-form.blade.php and create this file

<!DOCTYPE html>
<html>
<head>
<title>Laravel 8 Form Example Tutorial laravel Amit</title>
<meta name="csrf-token" content="{{ csrf_token() }}">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

</head>
<body>

<div class="container mt-4">

@if(session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif

<div class="card">
<div class="card-header text-center font-weight-bold">
Laravel 8 - Add Blog Post Form Example
</div>
<div class="card-body">
<form name="add-blog-post-form" id="add-blog-post-form" method="post" action="{{url('store-form')}}">
@csrf

<div class="form-group">
<label for="exampleInputEmail1">Title</label>
<input type="text" id="title" name="title" class="form-control" required="">
</div>

<div class="form-group">
<label for="exampleInputEmail1">Description</label>
<textarea name="description" class="form-control" required=""></textarea>
</div>

<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</body>
</html>

Now refresh the Browser

php artisan serve

When you fire the above given url on browser, you will look like in the following image:

http://127.0.0.1:8000/add-blog-post-form

Thanks

Tagged : / / /

Expected response code 250 but got code “530”, with message “530 5.7.1 Authentication required

I got stuck on this error I trying to configure SMTP mail on laravel

here is my configuration on .env file

This is Solved this Error

your mail.php on config you declare host as smtp.mailgun.org and port is 587 while on env is different. you need to change your mail.php to

if you desire to use mailtrap.Then run this command

php artisan config:cache

env() helper makes the job and there is no need to change values in mail.php. Just ensure that all email settings in .env file are correct

Tagged : / /

Laravel Error:Integrity constraint violation

yesterday : when i am trying to submit data to store in database i got error integrity constraint violation rule

because role_id is foreign key and i did not mention this field in user model.

Solution: after role_id mention in user model my error got solved

https://gist.github.com/rakesh1166-cm/6e233a6d0f51504801713420cb483338#file-users-php

Tagged :

Target class [PostController] does not exist.

Whenever you got this types of error go to your Route/web.php file and checkout your Controller class is mention there or not.

Next Go to PostController file and copy your controller class

Now go to Routes/web.php and class this class

use App\Http\Controllers\PostController;
php artisan serve

Now its working properly

Thanks.

Tagged : / / / /

Laravel Passport Trying to get property ‘secret’ of non-object

THIS IS FOR LARAVEL 8 AND LARAVEL/PASSPORT

The first thing is to run the php artisan passport:install.

Inside your database table oauth_clients, under column name, look for Laravel Personal Access Client.

Copy the secret beside Laravel Personal Access Client.

Open AuthServiceProvider, then paste the secret inside the boot method where the CLIENT_SECRET is below:

Passport::personalAccessClientSecret(config('CLIENT_SECRET'));

And don’t forget to also add the ID of the secret from your database.

Passport::personalAccessClientId(config('ID'));

Use the quote along with the ID and CLIENT_SECRET as config() is expected to get a string.

Now is solved this error

Tagged : / /

Crud Operation in Laravel with Image Store laravel 5.8

In this tutorial I’m going to describe about crud operation how to install project and setup and create controller, models, migration and all the things please read it carefully and follow some easy steps.

Lets go to download project and set up to

composer create-project laravel/laravel form "5.8.*"

Next go to .env file and put your database name -> form

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=form
DB_USERNAME=root
DB_PASSWORD=

Next step create database in PhpMyAdmin Database name 👇

form

Now migrate the table run this command 👇

php artisan migrate

Table has been migrated successfully.

let’s go to create model, migration and controller in one command copy below code and paste in your terminal.

php artisan make:model product -mcr

Now migrate the table

php artisan migrate

Step 4: Add Resource Route

<?php

use App\Http\Controllers\ProductController;


/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
return view('welcome');
});


// Route::resource('products', ProductController::class);

Route::resource('products', ProductController::class);

Step 5: Go to Your Controller and paste below code in your controller file

<?php

namespace App\Http\Controllers;

use App\Product;
use Illuminate\Http\Request;

class ProductController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$products = Product::latest()->paginate(5);

return view('products.index',compact('products'))
->with('i', (request()->input('page', 1) - 1) * 5);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('products.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'detail' => 'required',
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);

$input = $request->all();

if ($image = $request->file('image')) {
$destinationPath = 'image/';
$profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
$image->move($destinationPath, $profileImage);
$input['image'] = "$profileImage";
}

Product::create($input);

return redirect()->route('products.index')
->with('success','Product created successfully.');
}

/**
* Display the specified resource.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function show(Product $product)
{
return view('products.show',compact('product'));
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function edit(Product $product)
{
return view('products.edit',compact('product'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Product $product)
{
$request->validate([
'name' => 'required',
'detail' => 'required'
]);

$input = $request->all();

if ($image = $request->file('image')) {
$destinationPath = 'image/';
$profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
$image->move($destinationPath, $profileImage);
$input['image'] = "$profileImage";
}else{
unset($input['image']);
}

$product->update($input);

return redirect()->route('products.index')
->with('success','Product updated successfully');
}

/**
* Remove the specified resource from storage.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function destroy(Product $product)
{
$product->delete();

return redirect()->route('products.index')
->with('success','Product deleted successfully');
}
}

Next go to model and paste in below code

app/Models/Product.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class product extends Model
{
protected $fillable = [
'name','detail','image'
];
}

Step 6: Add Blade Files

1) layout.blade.php

2) index.blade.php

3) create.blade.php

4) edit.blade.php

5) show.blade.php

resources/views/products/layout.blade.php

<!DOCTYPE html>
<html>
<head>
<title>Laravel Crud Operation laravel amit</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet">
</head>
<body>

<div class="container">
@yield('content')
</div>

</body>
</html>

resources/views/products/index.blade.php

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Laravel Crud Operation with Image store Laravel Amit</h2>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('products.create') }}"> Create New Product</a>
</div>
</div>
</div>

@if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
@endif

<table class="table table-bordered">
<tr>
<th>No</th>
<th>Image</th>
<th>Name</th>
<th>Details</th>
<th width="280px">Action</th>
</tr>
@foreach ($products as $product)
<tr>
<td>{{ ++$i }}</td>
<td><img src="/image/{{ $product->image }}" width="100px"></td>
<td>{{ $product->name }}</td>
<td>{{ $product->detail }}</td>
<td>
<form action="{{ route('products.destroy',$product->id) }}" method="POST">

<a class="btn btn-info" href="{{ route('products.show',$product->id) }}">Show</a>

<a class="btn btn-primary" href="{{ route('products.edit',$product->id) }}">Edit</a>

@csrf
@method('DELETE')

<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</table>

{!! $products->links() !!}

@endsection

resources/views/products/create.blade.php

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Add New Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('products.index') }}"> Back</a>
</div>
</div>
</div>

@if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif

<form action="{{ route('products.store') }}" method="POST" enctype="multipart/form-data">
@csrf

<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
<input type="text" name="name" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Detail:</strong>
<textarea class="form-control" style="height:150px" name="detail" placeholder="Detail"></textarea>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Image:</strong>
<input type="file" name="image" class="form-control" placeholder="image">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>

</form>
@endsection

resources/views/products/edit.blade.php

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Edit Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('products.index') }}"> Back</a>
</div>
</div>
</div>

@if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif

<form action="{{ route('products.update',$product->id) }}" method="POST" enctype="multipart/form-data">
@csrf
@method('PUT')

<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
<input type="text" name="name" value="{{ $product->name }}" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Detail:</strong>
<textarea class="form-control" style="height:150px" name="detail" placeholder="Detail">{{ $product->detail }}</textarea>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Image:</strong>
<input type="file" name="image" class="form-control" placeholder="image">
<img src="/image/{{ $product->image }}" width="300px">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>

</form>
@endsection

resources/views/products/show.blade.php

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2> Show Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('products.index') }}"> Back</a>
</div>
</div>
</div>

<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
{{ $product->name }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Details:</strong>
{{ $product->detail }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Image:</strong>
<img src="/image/{{ $product->image }}" width="500px">
</div>
</div>
</div>
@endsection

Now php artisan serve

http://localhost:8000/products

Now its open look like this 👇

Thanks 🙏🙏

Tagged : / / / /

Top 10 Interview Question in Laravel 2021?

Q #1) What is Laravel?.

Laravel is a free and open-source PHP framework that is utilized to developed wide variety of web applications. Laravel is an accessible language for new programmers because the laravel community provides lots of modules resources are free available. Laravel provides a simple way to authorization logic and control access to resources with a simple ActiveRecord implementation that makes their interaction with databases.

Q #2) Define Composer.

Composer is a dependency manager for php framework. Composer runs through the command line. The main purpose of the composer is to install the dependencies or libraries for an application. Composer help to install required package component whatever you want to install in your application.

Q #3) What is Routing?

Route is a way to create request URL of your application, Route is a method of accepting a request and sending it to the relevant function in the controller.

What are the two main routing files in Laravel?

1. web.php
2. api.php

Q #4) What is a CSRF token?

Answer: CSRF is an abbreviation for Cross-Site Request Forgery that is generated by the server-side application and transmitted to the client. A CSRF token is a unique value that is generated by the server-side of the application and sent to the client

CSRF token helps to protect web applications from attacks which force a user to perform an unwanted action (commonly known as CSRF attacks).

Q #5) What is an artisan?

Artisan is the command-line tool for Laravel to help the developer build the application use while developing your application. You can enter the below command to get all the available commands:

example of commands

php artisan make:controller — Make Controller file
php artisan make:model

Q #6) How to put Laravel applications in maintenance mode?

php artisan down

And can put the application again on live using the below command:

php artisan up

Q #7) How to put Laravel applications in maintenance mode?

What are the default route files in Laravel?

web.php — For registering web routes.
api.php — For registering API routes.
console.php — For registering closure-based console commands.
channel.php — For registering all your event broadcasting channels that your application supports.

Q #8) What are seeders in Laravel?

Seeders in laravel are used to put dummy data in the database tables automatically. After running migrations to create the tables, we can run `php artisan db:seed` to run the seeder to populate the database tables.

We can create a new Seeder using the below artisan command:

php artisan make:seeder [className]

Q #9) List out common artisan commands used in Laravel.

Laravel supports following artisan commands:

PHP artisan down;
PHP artisan up;
PHP artisan make:controller;
PHP artisan make:model;
PHP artisan make:migration;
PHP artisan make:middleware;

Q #10) What is the Latest version of Laravel?

Answer: Laravel 8 is the latest version.

Thanks… 👍👍

Tagged : / / / / /

file_put_contents(C:\xampp\htdocs\exam_system\storage\framework/sessions/FF): failed to open stream: No such file or directory => Soled this Error

Step 1: type your TERMINAL this Command

composer update

Step 2: type your TERMINAL this Command

php artisan r:clear

Step 3: type your TERMINAL this Command

php artisan v:clear

Step 4: type your TERMINAL this Command

php artisan c:Cache

Now is your Project is Running

Tagged : / / /