General error: 1364 Field ‘phone’ doesn’t have a default value

SQLSTATE[HY000]: General error: 1364 Field ‘phone’ doesn’t have a default value (SQL: insert into `products` (`name`, `email`, `address`, `image`, `updated_at`, `created_at`) values (amti, kuam@gmail.com, sdafasdf, 642917381.jpg, 2021–05–11 10:58:35, 2021–05–11 10:58:35))

When I’m submit form then got General error field doesn’t have default value. let’s go to solve this.

👉 1 step go to your database and put change none>to Null and save.

Lets go to phpmyadmin

👉 Click on Structure

Click on change and change all field to None to Null and save

Set Null and click on save button

👁👁 Now its error has been solved and your data has been stored successfully.

Thanks

Tagged : / / / / / /

How to Store Multiple Records using Checkbox in Laravel?

First Part: first of all, we will learn how to design or getdata in blade file

In table we will set one field default value as no while migrating data

test_migration.php

In blade file we will create one table

Next, in js we will create one fetch function

onclick java script function

Routing:set route

Route::prefix(‘/touroperator’)->group(function () use ($namespace) {

$controller = $namespace.'\TourDashboardController';
$tourcontroller = $namespace.'\TourDetailController';

Route::get(‘toursdetail/{email}’,”$tourcontroller@gettrip”);


});

create function in client side controller

Set env file:

GET_MYHOLIDAYTRIP_URL=/api/v1/j/gettripdetail

Set Config file:

GET_MYHOLIDAYTRIP_URL’ => env(‘GET_MYHOLIDAYTRIP_URL’, ‘not found in .env file’),

Routing set Server side:

Route::get(‘gettripdetail/{email}’, ‘Admin\AdminTPController@tripdetail’);

Create function in server side:

Second Part: thereafter, we will learn how to store data after selecting in blade file

Set Routing(Client side microservice) :

Route::prefix(‘/touroperator’)->group(function () use ($namespace) {

$controller = $namespace.'\TourDashboardController';
$tourcontroller = $namespace.'\TourDetailController';

Route::post(‘permissiontour/{email}’, ‘AdminController@addpermission’)->name(‘permissiontour’);
});

Create function in client side controller

Set Env file

PERMIT_TRIP_URL=/api/v1/j/permittrip

config file:

‘PERMIT_TRIP_URL’ => env(‘PERMIT_TRIP_URL’, ‘not found in .env file’), 

Set Routing in server side Microservice

Route::post(‘/permittrip’, ‘Admin\AdminTPController@storepermission’);

Create function in controller server side microservice

Tagged : /

Laravel Error: Creating default object from empty value when store data

today,I am updating data in one table(package table), but I wrote different modal name Trip Category

So,be careful while you are updating data ,choose correct modal name

Tagged :

How to update multiple table rows using single edit button In Laravel Microservice

I have three table package,addimage,iternaries and triptitle is foreign key(common key) for all three table. my requirement is if i update package table using edit button then automatically updated addimage,iternaries table

In above figure 3 table package,addimage,iternaries and trip title and trips are foreign key i want to update those row whose triptitle or trips name is couple tour

refrence:https://stackoverflow.com/questions/45912985/laravel-update-array-syntax/45913079

Tagged :

How to delete multiple table rows using one delete button In Laravel Microservice

I have three table package,addimage,iternaries and triptitle is foreign key(common key) for all three table. my requirement is if i delete package table using delete button
then automatically deleted addimage,iternaries table

In above figure 3 table package,addimage,iternaries and trip title and trips are foreign key i want to delete those row whose triptitle or trips name is couple tour

Query:

Tagged :

HTML tags showing in my public view when I am using Ckeditor to store data in database.

profile.blade.php

{{$users->quality}}

Solution:

Use below codes to hide html tags

{!!$users->quality!!}

Resources :

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

ERROR: Unable to store image in particular directory

today when i storing image then one error appears

Solution:I have given permission to that directory folder public folder after that my issue is resolved

chmod -R 777 ./public

refrence:https://stackoverflow.com/questions/34836602/laravel-uploading-file-unable-to-write-in-directory

Tagged : /

Crud Operation in Laravel

In this tutorial I’m going to learn how to create Crud operation in Laravel. Please follow some easy steps define below.

Step 1 — Installing Laravel 8

Open terminal in xampp/htdocs and paste below code

composer create-project laravel/laravel example-app

Step 2 — Setting up a MySQL Database

👇 Step 2 — Database Configuration

Setup database with your installed laravel 8 project . lets go to .env folder and put database name and connect to database.

👇 Next go to .env folder and put database name

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=crud-operation
DB_USERNAME=root
DB_PASSWORD=

Next run this command

php artisan migrate

Step 3 — Creating a Database Migration

Run this command

php artisan make:migration create_products_table --create=products

Copy below code and simply paste in your products table

<?php

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

class CreateProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->text('detail');
$table->timestamps();
});
}

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

Step 4 — Adding a Resource Route

<?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::resource('products','ProductController');

Step 5 — Adding a Laravel 8 Controller and Model

run this command

php artisan make:controller ProductController --resource --model=Product

Go to your product controller and paste below code

<?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',
]);

Product::create($request->all());

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',
]);

$product->update($request->all());

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');
}
}

Lets Go to Model and paste below code

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

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

Step 6 — Adding your Larevl 8 Blade Views

Go to Resource folder and create view file

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 6 CRUD Application - 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 6 CRUD Example from By 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>Name</th>
<th>Details</th>
<th width="280px">Action</th>
</tr>
@foreach ($products as $product)
<tr>
<td>{{ ++$i }}</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">
@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 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">
@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 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>
@endsection

Lets run php artisan serve

http://localhost:8000/products

I hope its helpful for you.

Tagged : / / /

How to set read more button using data from database in Laravel?

Hi friends, I want to add read more… button in my blade file where data is coming from database.

below is my code in blade file getalldata.blade.php

<ul class="text-justify">
	<li>
        <small>{{$users->pro_experience}}</small>
    </li>
</ul>

In above Unordered list I am getting a long data from database and I want to add a Read more and Read Less toggle option. Now follow below steps to get your result now.

getalldata.blade.php

<ul class="text-justify">
	<li class="">
		<!-- <small>{{$users->pro_experience}}</small> -->
		@if(strlen($users->pro_experience) > 50)
			{{substr($users->pro_experience,0,50)}}
			<span class="read-more-show hide_content">More<i class="fa fa-angle-down"></i></span>
			<span class="read-more-content"> {{substr($users->pro_experience,50,strlen($users->pro_experience))}} 
			<span class="read-more-hide hide_content">Less <i class="fa fa-angle-up"></i></span> </span>
		@else
			{{$users->pro_experience}}
		@endif
	</li>
</ul>

Javascript Code

<script type="text/javascript">
// Hide the extra content initially:
            $('.read-more-content').addClass('hide_content')
            $('.read-more-show, .read-more-hide').removeClass('hide_content')

            // Set up the toggle effect:
            $('.read-more-show').on('click', function(e) {
              $(this).next('.read-more-content').removeClass('hide_content');
              $(this).addClass('hide_content');
              e.preventDefault();
            });
            $('.read-more-hide').on('click', function(e) {
              var p = $(this).parent('.read-more-content');
              p.addClass('hide_content');
              p.prev('.read-more-show').removeClass('hide_content'); // Hide only the preceding "Read More"
              e.preventDefault();
            });
</script>

CSS Code

<style type="text/css">
    .read-more-show{
      cursor:pointer;
      color: #ed8323;
    }
    .read-more-hide{
      cursor:pointer;
      color: #ed8323;
    }

    .hide_content{
      display: none;
    }
</style>

Resources :

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