Skip to content

Commit

Permalink
move image to correct folder
Browse files Browse the repository at this point in the history
  • Loading branch information
iserifith committed Aug 24, 2018
1 parent 07b630c commit 9bc71a3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/Http/Controllers/GenerateUrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public function store(Request $request)

$url = DB::transaction(function () use ($request) {
if (isset($request->image)) {
$pathName = $request->image->store('meta');
$pathName = $request->image->store('meta', 'public');

}

if ($request->type === 'single') {
Expand Down Expand Up @@ -231,7 +232,7 @@ public function update(Request $request, ShortenedUrl $url)
$url = DB::transaction(function () use ($request, $url) {

if ($request->hasFile('image')) {
$pathName = $request->image->store('meta');
$pathName = $request->image->store('meta', 'public');
}

$editUrl = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use App\ShortenedUrl;
use Illuminate\Database\Migrations\Migration;

class MoveImageToCorrectStorage extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$urls = ShortenedUrl::withTrashed()->get();

foreach ($urls as $url) {
if (!preg_match('/^meta\//', $url->image) && $url->image === !null) {
rename(public_path('images/og/' . $url->image), storage_path('app/public/meta/' . $url->image));
$url->image = 'meta/' . $url->image;
$url->save();

} else if (preg_match('/^meta\//', $url->image)) {
rename(storage_path('app/' . $url->image), storage_path('app/public/' . $url->image));

}
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
2 changes: 1 addition & 1 deletion resources/views/partials/customFacebookMeta.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<meta property="og:type" content="website" />
<meta property="og:title" content="{{ $url->title }}" />
<meta property="og:description" content="{{ $url->description }}" />
<meta property="og:image" content="{{ asset($url->image ? 'images/og/' . $url->image : 'images/jomwasap.png') }}" />
<meta property="og:image" content="{{ asset($url->image ? 'storage/' . $url->image : 'images/jomwasap.png') }}" />

0 comments on commit 9bc71a3

Please sign in to comment.