小编Sun*_*shi的帖子

如何在 Laravel 5.4 中验证文件名

我有一个包含三个输入字段的表单。我想在处理它们之前验证输入值。我想在处理之前验证文件名的地方。我使用正则表达式和 alpha_dash。但是我收到一个有效文件名的错误。我希望我的文件名只包含小写字母、数字、下划线和破折号。如何检查文件名的有效性?

html

 <form action="create" method="POST"  enctype="multipart/form-data">
          {{csrf_field()}}
      <table cellpadding="2" width="20%"  align="center"
         cellspacing="2">

         <tr>
           <td colspan=2>
           <center><font size=4><b>Add the iteams  please</b></font></center>
           </td>
         </tr>

         <tr>
           <td>Heading</td>
           <td><input type="text" name="heading" id="heading" size="30">
           {!! $errors->first('heading', '<p class="red">:message</p>') !!}
           </td>
         </tr>

         <tr>
           <td>Image</td>
           <td><input type="file" name="image" id="image" size="40">
           {!! $errors->first('image', '<p class="red">:message</p>') !!}
           </td>
         </tr>

         <tr>
           <td></td>
           <td colspan="2"><input type="submit" name="submit" value="Add Item" /></td>
         </tr>
     </table>
 </form>
Run Code Online (Sandbox Code Playgroud)

控制器部分

  1. 使用正则表达式格式:

- 我收到错误消息,“图像格式无效”。

 public function store(){
    $this->validate(request(),[
          'heading'=>'required',
          'contentbody'=>'required',
           ‘image'=>['required','image','mimes:jpeg,png,jpg,gif,svg','max:2048','regex:/^[a-z0-9-_]+$/' ]

        ]);

}
Run Code Online (Sandbox Code Playgroud)
  1. 使用 Alpa_dash:

- …

php regex laravel laravel-5 laravel-5.4

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

在laravel中的RESTful控制器和路由

我来自codeigniter,并试图绕过路由.我正在关注 http://codehappy.daylerees.com/using-controllers教程

如果向下滚动到RESTful控制器,Dayle将讨论Home_Controller扩展base_controller并添加公共函数get_index()和post_index().我复制了代码,但是当我去的时候

http://localhost/m1/public/account/superwelcome/Dayle/Wales 
Run Code Online (Sandbox Code Playgroud)

我明白了:

我们走错了路.服务器错误:404(未找到).

有什么明显的我做错了吗?我应该把代码放在其他地方吗?这是我的代码

class Base_Controller extends Controller {

    /**
     * Catch-all method for requests that can't be matched.
     *
     * @param  string    $method
     * @param  array     $parameters
     * @return Response
     */
     public function __call($method, $parameters)
     {
       return Response::error('404');
     }

     public $restful = true;

     public function get_index()
     {
       //
     }
     public function post_index()
     {
       //
     }

}
Run Code Online (Sandbox Code Playgroud)

在routes.php文件中,我有:

// application/routes.php
Route::get('superwelcome/(:any)/(:any)', 'account@welcome');
Run Code Online (Sandbox Code Playgroud)

我的帐户控制器(来自教程)是:

// application/controllers/account.php
class Account_Controller extends Base_Controller
{
       public function action_index()
       {
          echo "This …
Run Code Online (Sandbox Code Playgroud)

php rest laravel

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

Laravel created_at 格式

我在一个 Laravel 站点工作,我只是想知道是否有办法为用户格式化 created_at 值,因为现在它是这样的:

2017-09-20 13:41 
Run Code Online (Sandbox Code Playgroud)

但我更愿意将其格式化为易于阅读的格式,例如

20th September 2017 13:41 (or 01:41pm if possible)
Run Code Online (Sandbox Code Playgroud)

谁能帮我这个?

提前致谢

laravel

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

标签 统计

laravel ×3

php ×2

laravel-5 ×1

laravel-5.4 ×1

regex ×1

rest ×1