小编Jam*_*ady的帖子

在Laravel视图中使用CSS?

我刚开始学习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仍未显示!

我怎样才能克服这个问题,并且变得更好 - 因为我正在慢慢地学习这个框架.

php frameworks laravel

102
推荐指数
11
解决办法
27万
查看次数

Laravel 验证总是从 API 返回 200 OK

我想将我的验证器与我的控制器分开,但 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)

php validation laravel

9
推荐指数
4
解决办法
1万
查看次数

如何在Laravel Homestead中使用postgreSQL

我可以迁移到我的家园.这是我的.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)

php postgresql laravel homestead

8
推荐指数
1
解决办法
3257
查看次数

Laravel在控制器中手动检查CSRF

我正在使用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 ..提前谢谢,抱歉我的英语不好.

php node.js socket.io laravel

6
推荐指数
1
解决办法
870
查看次数

为数组添加值

我是编码新手,请耐心等待.我做了一个看起来像这样的数组:

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然后按打印,结果将是:嗨.

任何能够推动我正确方向的人?

html javascript

3
推荐指数
1
解决办法
86
查看次数

如何在cmd中登录postgresql

我是laravel用户。我使用homestead运行项目,并且使用porstgreSQL作为数据库。我psql -U homestead -h localhost在cmd中运行,然后输入secret密码。但是我有这样的错误

psql:致命:用户“ homestead”的密码身份验证失败

postgresql laravel homestead

0
推荐指数
1
解决办法
3161
查看次数

如何在 Laravel 中更新具有不同 ID 的多行

这是我问的最后一个问题..

我有一张会员表

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)

当我尝试更新时,出现数组到字符串转换错误。

php laravel

0
推荐指数
2
解决办法
2万
查看次数