小编maf*_*tis的帖子

laravel 不会在服务器上上传图片

我可以在本地工作时上传我的图片,但是当我将我的网站移动到主机时,它不会上传图片,同时在数据库中获取它们的名称,

我的 filesystems.php

'default' => env('FILESYSTEM_DRIVER', 'local'),
disks' => [

        'local' => [
            'driver' => 'local',
            'root' => public_path('images/'),
        ],
....
Run Code Online (Sandbox Code Playgroud)

我的上传代码示例:

if ($request->hasFile('imageOne')) {
  $imageOne = $request->file('imageOne');
  $filename = 'productone' . '-' . time() . '.' . $imageOne->getClientOriginalExtension();
  $location = public_path('images/');
  $request->file('imageOne')->move($location, $filename);
  $product->imageOne = $filename;
}
Run Code Online (Sandbox Code Playgroud)

问题:

在主机中,我上传了image name in database,但我的public/images文件夹中没有图像 。

任何的想法?

更新

我发现有趣的文件夹在我的主人,我提出我的所有public文件夹中的文件服务器public_html,现在它在我的根呼吁创建另一个文件夹public以及里面有images文件夹,包括我上载到目前为止,所有的图像!

问题:

  1. 为什么 Laravelpublic/images在我的根目录中创建了新文件夹而不是使用我的public_html?
  2. 如何解决?

php laravel

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

AMP 不允许加载图像

\n\n

我正在尝试在我的应用程序中使用AMP。我可以通过以下方式获取图像:

\n\n
<img src="{{url(\'storage/images\')}}/{{$post->image}}" alt="{{$post->title}}" class="img-fluid">\n
Run Code Online (Sandbox Code Playgroud)\n\n

但由于我添加了 AMP,它们将不再加载:

\n\n
<amp-img src="{{url(\'storage/images\')}}/{{$post->image}}" alt="{{$post->title}}" class="img-fluid"></amp-img>\n
Run Code Online (Sandbox Code Playgroud)\n\n

知道发生了什么吗?

\n\n

更新1

\n\n

这是我添加到我的网站标题中的内容:

\n\n
<html amp lang="{{ app()->getLocale() }}">\n<!-- amp -->\n    <script async src="https://cdn.ampproject.org/v0.js"></script><!-- must besecond child -->\n    <link rel="canonical" href="{{url()->current()}}">\n    <script type="application/ld+json">\n      {\n        "@context": "http://schema.org",\n        "@type": "NewsArticle",\n        "headline": "Open-source framework for publishing content",\n        "datePublished": "2015-10-07T12:02:41Z",\n        "image": [\n          "logo.jpg"\n        ]\n      }\n    </script>\n    <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 …
Run Code Online (Sandbox Code Playgroud)

amp-html amp-img

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

Laravel 按时间获取数据

我需要获取从 10 分钟前到现在创建的数据,但它返回错误的结果

$defs = OrderDefaultProgress::where('name', 'Laundry Mencari supir')->pluck('id')->toArray();
$progresses = OrderProgress::where('created_at', '<=', Carbon::now()->subMinutes(10))->whereIn('progress_id', $defs)->get();
Run Code Online (Sandbox Code Playgroud)

$progresses返回带有时间戳的2021-02-07T09:15:44.000000Z数据,而此数据属于 8 小时前。

[
    {
        "id": "7ce3bd58-3f19-4de9-8b92-e196d6e7b97f",
        "order_id": "175fe9ed-6932-4d5e-ba8f-ec36acf7d872",
        "progress_id": "b816f3bf-9c58-4e77-8d67-b834cac4ae77",
        "created_at": "2021-02-07T09:15:44.000000Z",
        "updated_at": "2021-02-07T09:15:44.000000Z"
    }
]
Run Code Online (Sandbox Code Playgroud)

奇怪的是,在我的数据库中,我什至没有这样的时间戳!

一

php laravel

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

Laravel存储链接不适用于生产

storage_path用来保存图像,并将我的存储文件夹象征性地保存到public_html

php artisan storage:link
Run Code Online (Sandbox Code Playgroud)

在本地,一切正常,当我上载图像时,它将上载到存储文件夹中,并且其链接将出现在public文件夹中,但是由于我移至实时主机和生产模式,因此我的图像将上载到存储文件夹中,但我public_html/storage和我都没有我无法让他们进入我的前端。

代号

/config/filesystems.php

'public' => [
  'driver' => 'local',
  'root' => storage_path('app/public/'),
  'url' => env('APP_URL').'/storage',
  'visibility' => 'public',
],
Run Code Online (Sandbox Code Playgroud)

.env

FILESYSTEM_DRIVER=public
Run Code Online (Sandbox Code Playgroud)

controller sample

if ($request->hasFile('image')) {
  $image = $request->file('image');
  $filename = 'page' . '-' . time() . '.' . $image->getClientOriginalExtension();
  $location = storage_path('app/public/images/' . $filename);
  Image::make($image)->resize(1200, 600)->save($location);
  if(!empty($page->image)){
    Storage::delete('images/' . $page->image);
  }
  $page->image = $filename;            
}
Run Code Online (Sandbox Code Playgroud)

任何的想法?

php laravel

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

Laravel护照和Vue登录

我已经在laravel中使用passport api进行了登录功能,并且状态为200,问题是我不知道如何在成功请求后登录用户并重定向到主页(我正在使用vuejs组件)

controller

public function login(Request $request)
    {
        $credentials = [
            'email' => $request->email,
            'password' => $request->password
        ];

        if (Auth::attempt($credentials)) {
            // $token = auth()->user()->createToken('AppName')->accessToken;
            // $success['token'] =  $token;
            // $success['name'] =  auth()->user()->name;
            // $success['id'] =  auth()->user()->id;
          $user = Auth::user();
            $success['token'] = $user->createToken('AppName')->accessToken;
            $success['user'] = $user;
            return response()->json(['success'=>$success], 200);
        } else {
            return response()->json(['error' => 'UnAuthorised'], 401);
        }
    }
Run Code Online (Sandbox Code Playgroud)

component script

<script>
    import {login} from '../../helpers/Auth';

    export default {
        name: "login",
        data() {
            return { …
Run Code Online (Sandbox Code Playgroud)

authentication oauth-2.0 laravel vue.js laravel-passport

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

laravel批量更新问题

我试图在laravel中批量更新我的数据,但我需要帮助在更新方法中找到我的数据ID并匹配它们.

这是我发送的数据的dd结果:

array:5 [?
  "_method" => "PUT"
  "_token" => "exywo7qYEh69QEZscfxrbiLDzavGdihSLzpeOxlT"
  "title" => "tjd group"
  "vall" => array:7 [?
    0 => "val 1"
    1 => "val 2"
    2 => "val 3"
    3 => "val 4"
    4 => "val 5"
    5 => "val 6"
    6 => "val 7"
  ]
  "vall_id" => array:7 [?
    0 => "27"
    1 => "28"
    2 => "29"
    3 => "30"
    4 => "31"
    5 => "32"
    6 => "33"
  ]
]
Run Code Online (Sandbox Code Playgroud)

逻辑

  1. valls 是属性(在这种情况下tjd组中我的组的子项)
  2. vall_idvall …

php laravel

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

laravel中的总和

sessions该如何求和这个数组的值?

Collection {#3646 ?
  #items: array:2 [?
    0 => array:2 [?
      "type" => "New Visitor"
      "sessions" => 154
    ]
    1 => array:2 [?
      "type" => "Returning Visitor"
      "sessions" => 59
    ]
  ]
}
Run Code Online (Sandbox Code Playgroud)

$analyticsData4 = Analytics::fetchUserTypes(Period::months(1));
Run Code Online (Sandbox Code Playgroud)

这段代码返回上面的dd.我需要总结会话值New Visitors and Returning Visitors

sum laravel

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

在laravel中将请求转换为Json

我想将来自表单的多个请求存储为 json 形式的单列。我知道我可以使用toJson但那是为了防止您从数据库返回数据。就我而言,我的数据来自类似的形式$request->input(\'address_id\');

\n\n
//incoming data\narray:8 [\xe2\x96\xbc\n  "address_id" => "3"\n  "weight" => "3"\n  "shipping_cost" => "9000"\n]\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n

上面的数据只是示例(我有更多输入,但假设我只需要 \n 制作这 3 个输入的 JSON)

\n
\n\n

我怎样才能做到这一点?

\n

php json laravel

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

角清晰阵列

我试图在删除和刷新按钮上刷新我的页面,它获取新数据但问题是new data will add to old ones我需要在添加新数据之前清除旧数据。

代码

addresses: any[] = [];

// loads first time data
this.addressService.getAddresses().subscribe((res) => {
  for (let address of res['data']) {
    this.addresses.push(address);
  }
  this.hideLoading();
});

// refresh list items
doRefresh(event) {
console.log('Begin async operation');

setTimeout(() => {
    console.log('Async operation has ended');

// get new items in list
    this.addressService.getAddresses().subscribe((res) => {
    for (let address of res['data']) {
        this.addresses.push(address);
    }
    this.hideLoading();
    });

    event.target.complete();
}, 2000);
}

//remove item and renew list items
removeAddress(id: string){
this.addressService.remove(id).subscribe( …
Run Code Online (Sandbox Code Playgroud)

javascript ionic-framework angular

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

API 数据的 Kotlin 类

我有以下结构的 API 数据:

{
    "data": [
        {
            "id": "a3d9b20a-f84c-483e-81af-f8d6a7e2de0f",
            "amount": 11000,
            "transport": 29000,
            "total": 183000,
            "weight": 14,
            "payment": "Cash",
            "payment_id": null,
            "payment_method": null,
            "accepted": 0,
            "customer": {
                "id": "2c8693d9-76ff-4bad-b7bd-bc3a1446a5e5",
                "name": "Admin",
                "store": false,
                "phone": null,
                "photo": null,
                "email": "admin@admin.com",
                "address": null,
                "role": "admin",
                "created_at": "2021-01-27T03:50:24.000000Z"
            },
            "laundry": {
                "id": "acfa7e2e-aeb9-40d6-a68c-b6c259468b6b",
                "name": "Test 01",
                "email": "gfg@jhjgj.gfu",
                "phone": "5344454",
                "address": "gfvfggfggkh",
                "photo": "http://example.com/images/3a1690bd48161f941b99af72c0098e34-1611653771.jpg",
                "verified": 1,
                "created_at": "2021-01-26T02:36:12.000000Z"
            },
            "driver": {
                "id": "7c5715e2-2e73-4103-a439-bc54d9982552",
                "dob": "17-11-1888",
                "gender": "male",
                "expire_date": "11 22",
                "plat_nu": "F 4152 …
Run Code Online (Sandbox Code Playgroud)

android kotlin

-1
推荐指数
1
解决办法
57
查看次数