我有一些必须在表中的数据,以便我的应用程序工作,否则我收到一条错误消息.
例如,如果你或其他任何人从github拉我的应用程序,如果你运行php artisan migrate然后尝试测试应用程序你会得到一个错误:数据不存在或类似的东西.这是因为表中没有数据.
理想的解决方案是运行后:
php artisan migrate
Run Code Online (Sandbox Code Playgroud)
您还可以在该表中获得所需的数据.
这应该用播种机以某种方式完成,但我不知道如何.任何人都可以帮忙并举个例子吗?
如何为应该进入car_company表的数据制作种子:
id car_company
1大众汽车
2辆梅赛德斯
3奥迪
4保时捷
有4行,我想在运行后插入它们
php artisan db:seed
Run Code Online (Sandbox Code Playgroud) 我知道如何序列化整个表单,如下面的示例所示,或通过更改行来序列化表单的一个特定字段:
data: $('form').serialize(),
Run Code Online (Sandbox Code Playgroud)
到
data: $('#input-field').serialize(),
Run Code Online (Sandbox Code Playgroud)
。
$(document).on('input paste', '#soap', function () {
$.ajax({
type:'POST',
url:'/soap',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: $('form').serialize(),
success:function(data){
$('input[id=msg]').val(data.msg);
}
});
});
Run Code Online (Sandbox Code Playgroud)
但我想序列化 2 个具有 id 的输入字段......该怎么做?
因此,正如问题所言...当用户单击Web浏览器中的链接时,是否可以在后台运行php artisan命令?
例如,我想在我的应用程序中创建一个用于迁移迁移文件的按钮,以便在单击此按钮时:
<a href="/migrate" class="btn btn-primary">Migrate</a>
Run Code Online (Sandbox Code Playgroud)
我想跑步
php artisan migrate
Run Code Online (Sandbox Code Playgroud)
在背景中。
这可能吗?
我想通过 jquery 和 ajax 使用复选框切换表中的布尔值。
因此,每当用户勾选复选框时,它应该切换表中的值。
到目前为止,我想出了这个,但我需要帮助:
$(document).ready(function(){
$("input:checkbox").change(function() {
var isChecked = $("input:checkbox").is(":checked") ? 1:0;
$.ajax({
type:'POST',
url:'/activation',
headers: {'X-CSRF-TOKEN': '{{ csrf_token() }}' },
data: $('.checkbox').serialize(),
success:function(data){
}
});
});
});
Run Code Online (Sandbox Code Playgroud) 试图在 Laravel 中为日期创建一个 mutator,但它不起作用。
这是我的例子
public function getEventEndAttribute($date)
{
return Carbon::parse($date)->format('d.m.Y H:i')
}
Run Code Online (Sandbox Code Playgroud)
例如,在我的 User 模型中,我有一个完美运行的 mutator:
// convert email address to lowercase
public function getEmailAttribute($value) {
return strtolower($value);
}
Run Code Online (Sandbox Code Playgroud)
因此,即使用户使用大写字母编写电子邮件,它也会被转换为小写字母......
我希望我的日期也一样......从 MySQL DB 格式转换为我的本地格式
这是从 SO 复制的,但仍然无效。请帮忙。
控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\UserRequest;
use Carbon\Carbon;
use Auth;
use DB;
class UserRequestsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//dd(DB::table('user_requests')->get());
return view('user-requests.index', ['userRequests' …Run Code Online (Sandbox Code Playgroud) 我无法弄清楚为什么这不起作用:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
if ($('#check').is(':checked')) {
$('p').hide();
} else {
$('p').show();
}
});
</script>
</head>
<body>
<input type="checkbox" id="check" />
<p>If you click on the checkbox, I will disappear.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我点击复选框时,它应该隐藏p标签,但它不会...这应该是这么简单,但后来又不是:(
我刚用这个命令安装了pod
sudo gem install cocoapods
Run Code Online (Sandbox Code Playgroud)
git从git仓库克隆了一个项目并运行pod install --verbose,我收到此错误:
Resolving dependencies of `Podfile`
[!] Unable to integrate the following embedded targets with their respective host targets (a host target is a "parent" target which embeds a "child" target like a framework or extension):
- MyApp (true) and OneSignalNotificationServiceExtension (false) do not both set use_frameworks!.
Run Code Online (Sandbox Code Playgroud)
因为这个原因,我无法在Xcode中获得这个应用塔.我收到此错误消息:
这是我的(唯一一个)Podfile
在put_frameworks之后!我得到这个:
我只是想了解这是为什么?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>close</title>
</head>
<body>
<h1>onbeforeunload</h1>
<script>
console.log("loaded");
window.onbeforeunload = confirmExit;
function confirmExit(){
console.log("closed");
return false;
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果您将此代码复制并保存为 .html 文件并在浏览器中运行它,并且不单击页面内部并关闭选项卡或浏览器,则 onbeforeunload 将不会触发!
但是,如果您在页面内单击一次,然后尝试关闭页面,则一切正常。
想象一下 .env 文件中有这样的内容:
DB_CONNECTION=global
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=global
DB_USERNAME=dbuser
DB_PASSWORD=password
Run Code Online (Sandbox Code Playgroud)
并且您内部还有一个config/database.php称为租户的连接。
现在,当我尝试登录时,我将连接切换到租户,并使用该数据库中的用户名和密码,我可以登录、注销,一切正常。
但现在我希望能够使用此租户数据库中不存在的用户登录。
我开始像这样重写 login() 函数:
提示:请记住,此时连接已设置为租户!
public function login(Request $request)
{
$parts = explode(':', $request['username']);
if ($parts[0] === 'global') {
\DB::purge(\DB::getDatabaseName());
\DB::reconnect('global');
\Schema::connection('global')->getConnection()->reconnect();
}
::::::::::::::::::
Run Code Online (Sandbox Code Playgroud)
但这不起作用...它不会切换连接
我想使用全局数据库中的用户登录并继续使用租户数据库...
这可能吗?
我已经解决了如何切换数据库连接的部分...问题只是身份验证到另一个不同的连接!
在这个引导启动模板上:
当浏览器变窄时,导航栏链接/按钮会折叠为右上角的一个图标,如下所示:
我想把这个折叠的“图标”作为默认设置,就像上图一样。以便在用户单击右上角的折叠按钮后导航栏链接可用。
怎么做?
这是模板的源代码:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="starter-template">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this …Run Code Online (Sandbox Code Playgroud) 出于好奇,是否有可能做这样的事情:
$commands = [
strtolower('JUST TESTING'),
date('Y-m-d H:i:s'),
strtoupper('Done!'),
];
foreach ($commands as $command) {
$command;
}
Run Code Online (Sandbox Code Playgroud)
这当然行不通!有没有办法让它工作?
我的具体用例是这样的:
private function dropDatabasesAndMySQLUsers(): void
{
foreach ($this->getCommands() as $command) {
$command;
}
$this->info('Done! All app Databases and MySQL users are dropped');
}
public function getCommands(): array
{
return [
\DB::statement("DROP USER IF EXISTS 'myuser'@'localhost'"),
\DB::statement("DROP DATABASE IF EXISTS manager")
// I have about 20-30 of these
];
}
Run Code Online (Sandbox Code Playgroud) jquery ×3
laravel ×3
php ×3
ajax ×2
alias ×1
checkbox ×1
cocoapods ×1
date ×1
html ×1
ios ×1
javascript ×1
laravel-5 ×1
laravel-5.3 ×1
multi-tenant ×1
mutators ×1
powershell ×1