1678881300
嗨朋友们,
在这个快速示例中,让我们看看 sweet alert 确认删除示例 laravel 10。您将学习 laravel 10 sweet alert 然后我将给出一个简单的示例和解决方案。这是甜蜜警报 cdn 的简单示例,用于在从 laravel blade 文件中删除任何行之前显示确认框警报。本文详细介绍了使用表中数据删除的 laravel 10 甜蜜警报框。
在这个例子中,我们将学习如何在 laravel 10 应用程序中删除用户之前打开一个甜蜜的警报。我将展示在 laravel 10 中使用 delete 的 sweet alert jquery 插件。我将在 laravel 10 中删除用户之前展示一个简单的 sweet alert 示例。
让我们从头开始逐步在 Laravel 10、Laravel 9、Laravel 8、Laravel 7 中使用 Sweet Alert 删除方法。
第 1 步:下载 Laravel
让我们通过安装一个新的 Laravel 应用程序开始本教程。如果您已经创建了项目,则跳过以下步骤。
composer create-project laravel/laravel example-app
第 2 步:添加虚拟用户
在这一步中,我们需要使用工厂创建添加一些虚拟用户。
php artisan tinker
User::factory()->count(10)->create()
第 3 步:添加路线
在这一步中,我们需要创建一些用于添加到购物车功能的路线。
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
/*
|--------------------------------------------------------------------------
| 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('users', [UserController::class, 'index'])->name('users.index');
Route::delete('users/{id}', [UserController::class, 'delete'])->name('users.delete');
第 4 步:添加控制器
在此步骤中,我们需要创建 UserController 并在该文件中添加以下代码:
应用程序/Http/Controllers/UserController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
use DataTables;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$users = User::select("*")->paginate(8);
return view('users', compact('users'))->with('no', 1);
}
/**
* Write code on Method
*
* @return response()
*/
public function delete($id)
{
User::find($id)->delete();
return back();
}
}
第 5 步:添加刀片文件
在这里,我们需要为用户、产品和购物车页面创建刀片文件。所以让我们一个一个地创建文件:
资源/视图/users.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Laravel 10 Sweet Alert Confirm Delete Example - Nicesnippets.com</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/5.0.7/sweetalert2.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h3 class="text-center mt-4 mb-5">Laravel 10 Sweet Alert Confirm Delete Example - Nicesnippets.com</h3>
<table class="table table-bordered table-striped data-table">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Email</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{ $no++ }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td class="text-center">
<form method="POST" action="{{ route('users.delete', $user->id) }}">
@csrf
<input name="_method" type="hidden" value="DELETE">
<button type="submit" class="btn btn-xs btn-danger btn-flat show-alert-delete-box btn-sm" data-toggle="tooltip" title='Delete'>Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
<script type="text/javascript">
$('.show-alert-delete-box').click(function(event){
var form = $(this).closest("form");
var name = $(this).data("name");
event.preventDefault();
swal({
title: "Are you sure you want to delete this record?",
text: "If you delete this, it will be gone forever.",
icon: "warning",
type: "warning",
buttons: ["Cancel","Yes!"],
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((willDelete) => {
if (willDelete) {
form.submit();
}
});
});
</script>
</body>
</html>
运行 Laravel 应用程序:
所有步骤都已完成,现在您必须键入给定的命令并按回车键来运行 laravel 应用程序:
php artisan serve
现在,您必须打开 Web 浏览器,输入给定的 URL 并查看应用程序输出:
localhost:8000/users
输出:
我希望它可以帮助你...
文章原文出处:https: //www.nicesnippets.com/
1595201363
First thing, we will need a table and i am creating products table for this example. So run the following query to create table.
CREATE TABLE `products` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
Next, we will need to insert some dummy records in this table that will be deleted.
INSERT INTO `products` (`name`, `description`) VALUES
('Test product 1', 'Product description example1'),
('Test product 2', 'Product description example2'),
('Test product 3', 'Product description example3'),
('Test product 4', 'Product description example4'),
('Test product 5', 'Product description example5');
Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = [
'name','description'
];
}
Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.
routes/web.php
Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);
#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete
1600307091
How to install laravel 8 on windows 10. In this tutorial, i would love to share with you how to install laravel 8 on windows 10.
Installing laravel 8 on windows 10 xampp server step by step:
https://laratutorials.com/installing-laravel-8-on-windows-10-xampp/
#install laravel on windows xampp #how to install laravel in windows 10 xampp #install xampp on windows 10 laravel installation steps #laravel installation steps #how to run laravel project on localhost xampp
1621508419
Hire our expert team of Laravel app developers for flexible PHP applications across various cloud service providers.
With this easy build technology, we develop feature-rich apps that make your complex business process a lot easier. Our apps are,
Get your business a best in classlaravel app. Hire laravel app developers in India. We have the best organizational set-up to provide you the most advanced app development services.
#laravel app development company india #hire laravel developers india #laravel app development company #hire laravel developers #laravel development agency #laravel app programmers
1595220000
Tip 1. Controllers Having Single Action
In some situations you need a single action in a controller, if this is the case in Laravel you can achieve it by **__invoke()**
method.
<?php
namespace App\Http\Controllers;
use App\User;
use App\Http\Controllers\Controller;
class ShowProfile extends Controller
{
/**
* Show the profile for the given user.
*
* @param int $id
* @return Response
*/
public function __invoke($id)
{
return view('user.profile', ['user' => User::findOrFail($id)]);
}
}
Routes:
Route::get('user/{id}', 'ShowProfile');
Artisan command to generate this controller:
php artisan make:controller ShowProfile --invokable
Tip 2. Migration Fields Having Timezone
Do you know in Laravel migrations are just not limited to **timestamps()**
you can also add **timestampsTz()**
Schema::create('employees', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email');
$table->timestampsTz();
});
Also, there are columns **dateTimeTz()**
, **timeTz()**
, **timestampTz()**
, **softDeletesTz()**
.
Tip 3. Eloquent has() deeper
You can use Eloquent has() function to query relationships even two layers deep!
// Author -> hasMany(Book::class);
// Book -> hasMany(Rating::class);
$authors = Author::has('books.ratings')->get();
Tip 4. SoftDeletes: Restore Multiple
To restore soft deleted rows, you can restore them in one sentence.
User::withTrashed()->where('author_id', 1)->restore();
Tip 5. Image Validation
During image upload, validate images on specific dimensions.
'photo' => 'dimensions:max_width=4096,max_height=4096'
Tip 6. Wildcard Subdomains
You can create route group by dynamic subdomain name, and pass its value to every route.
Route::domain('{username}.workspace.com')->group(function () {
Route::get('user/{id}', function ($username, $id) {
//
});
});
#laravel #php #laravel quick tips #laravel tips #laravel tutorials #laravel tuts
1670234150
In the present world, PHP is a well-liked framework. Laravel is one of the most well-known frameworks out there. The popularity of Laravel is due to its expressiveness, flexibility, good controllers, strength, seamless caching, and time savings when handling tasks like routing, authentication, sessions, and many more.
Laravel is a PHP framework that everyone who knows PHP should be familiar with. The Laravel PHP framework is simple to learn and use, but it is packed with useful features. Despite rising market competition, many developers consider Laravel to be one of the best PHP frameworks available.
WPWeb Infotech is a top Laravel development company in India and the US since 2015. They develop reliable, scalable Laravel web and mobile apps using Ajax-enabled widgets, MVC patterns, and built-in tools. WPWeb Infotech has top-notch expertise in combining a variety of front- and back-end technologies like Laravel + VueJS, Laravel + Angular, and Laravel + ReactJS to create scalable and secure web architectures, so you don't have to worry about scalability and flexibility while developing your product. They understand business scale and recommend technology that fits. Agile experts reduce web and mobile app development time and risk.
When it comes to hiring Laravel developers from India, they are the best choice because their Laravel developers can work according to your time zone to provide you with hassle-free, innovative, and straightforward web development solutions. Being the most trusted Laravel development company in India, they can help you reach new heights of success, unleashing the power of the Laravel PHP framework.
Partner with one of India’s best Laravel Development Company and get the most expertise in Laravel development.
#laravel #laravel-development #laravel-development-company #laravel-development-services #hire-laravel-developers