我刚开始学习Laravel,可以完成控制器和路由的基础知识.
我的操作系统是Mac OS X Lion,它位于MAMP服务器上.
来自routes.php的代码:
Route::get('/', function() {
return View::make('home.index');
});
Route::get('businesses', function() {
return View::make('businesses.index');
});
Route::get('testing', function() {
return View::make('testing.index');
});
Route::get('hello', function() {
return "<h3>Hello world!</H3>";
});
Run Code Online (Sandbox Code Playgroud)
这有效,视图显示完美,''然而''我想要尝试和做的是在视图中包含CSS,我尝试添加到目录中的样式表的链接,但页面显示为默认浏览器字体甚至虽然CSS在HTML中!
这是来自views文件夹中的企业的index.php:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<p>Business is a varied term. My content here.
Run Code Online (Sandbox Code Playgroud)
我尝试在我的其他视图文件夹(测试)中使用Blade模板引擎来显示CSS但是尽管它在测试文件夹中,CSS仍未显示!
我怎样才能克服这个问题,并且变得更好 - 因为我正在慢慢地学习这个框架.
我想将我的验证器与我的控制器分开,但 API 总是200 OK在 Postman 中响应。
请求验证:
class PostRequest extends FormRequest
{
use Types;
public function authorize()
{
return true;
}
public function rules()
{
// $auth = $this->request->user();
return [
'name' => 'required|string|max:255',
'country_id' => 'required|exists:countries,id',
'city' => 'required|max:255',
'phone_no' => 'required|regex:/[0-9]{10,13}/',
'occupation' => 'required|max:255'
];
}
}
Run Code Online (Sandbox Code Playgroud)
发件人控制器:
public function store(PostRequest $request)
{
$auth = $request->user();
$sender = Sender::create([
'name' => $request->name,
'country_id' => $request->country_id,
'city' => $request->city,
'phone_no' => $request->phone_no,
'occupation' => $request->occupation …Run Code Online (Sandbox Code Playgroud) 我可以迁移到我的家园.这是我的.env
DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=54320
DB_DATABASE=intern
DB_USERNAME=homestead
DB_PASSWORD=secret
Run Code Online (Sandbox Code Playgroud)
我做一个新的服务器在我的PostgreSQL的与
server name = Homestead,
username = homestead,
password = secret.
Run Code Online (Sandbox Code Playgroud)
然后,我做了迁移,并将所有表创建到我的数据库(server = homestead)
问题是,当我想在我的网站上登录时.它发生错误:
SQLSTATE[08006] [7] could not connect to server: Connection refused?
Is the server running on host "localhost" (::1) and accepting?
TCP/IP connections on port 54320??could not connect to server: Connection refused?
Is the server running on host "localhost" (127.0.0.1) and accepting?
TCP/IP connections on port 54320? (SQL: select * from "users" where "email" = user@gmail.com …Run Code Online (Sandbox Code Playgroud) 我正在使用Laravel 5.5.当我从laravel刀片发送POST请求时.一切都很好:
$.post({
url: 'http://localhost/check',
data: {
_token: CSRF_TOKEN, // I have CSRF token variable above.
test: "it works"
}
})
Run Code Online (Sandbox Code Playgroud)
但我想用socket.io> node.js> laravel发送该请求:
socket.emit('checkPost', { token: CSRF_TOKEN });
Run Code Online (Sandbox Code Playgroud)
index.js
socket.on('checkPost', function (csrf) {
request.post({
url: 'http://localhost/check',
form: {
_token: csrf.token,
test: "it works"
}
});
});
Run Code Online (Sandbox Code Playgroud)
用ajax一切都好.在这里,我得到了令牌不匹配.为什么?
当我在VerifyCsrfTokenfor/check路由中禁用令牌验证时,节点请求也会起作用.
我该如何解决这个问题?也许有控制器csrf检查方法?然后我会检查控制器中的帖子csrf ..提前谢谢,抱歉我的英语不好.
我是编码新手,请耐心等待.我做了一个看起来像这样的数组:
var minArray = ["Hello", "Hi", "Yes", "No", "Good"];
function printit(number) {
document.getElementById('test').innerHTML = minArray[number];
}Run Code Online (Sandbox Code Playgroud)
<form name="f1">
<input type="text" value="" id="number" />
<input type="button" value="Word is:" onclick="printit(number)" />
</form>
<br/>
<div id="test" />Run Code Online (Sandbox Code Playgroud)
我想在文本字段中写入一个数字,然后从数组中获取该特定单词.因此,如果我写1然后按打印,结果将是:嗨.
任何能够推动我正确方向的人?
我是laravel用户。我使用homestead运行项目,并且使用porstgreSQL作为数据库。我psql -U homestead -h localhost在cmd中运行,然后输入secret密码。但是我有这样的错误
psql:致命:用户“ homestead”的密码身份验证失败
这是我问的最后一个问题..
我有一张会员表
Schema::create('role_memberships', function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id');
$table->string('MembershipName');
$table->text('MembershipValue');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
我有两行具有相同 role_id 的数据,我想更新两行这是我的控制器
$updateArray = [['MembershipValue' => $request->PostAdMaxImage],
['MembershipValue' => $request->PostAdExpiredDay]];
DB::table('role_memberships')->where('role_id', $id)-
>whereIn('role_id', $role->pluck('id'))->update($updateArray);
Run Code Online (Sandbox Code Playgroud)
当我尝试更新时,出现数组到字符串转换错误。
laravel ×6
php ×5
homestead ×2
postgresql ×2
frameworks ×1
html ×1
javascript ×1
node.js ×1
socket.io ×1
validation ×1