Created
July 19, 2017 15:31
-
-
Save fsuuaas/9f8b9cbb2b8bd5861da456283e3bde18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use App\Http\Requests; | |
use App\Model\Order; | |
use Session; | |
use Mail; | |
use Illuminate\Support\Facades\Auth; | |
class Images1Controller extends Controller | |
{ | |
public function __construct() { | |
$this->middleware('auth'); | |
} | |
public function doImageUpload(Request $request) { | |
//get the file from the post request | |
$file = $request->file('file'); | |
//set the file name | |
$filename = $file->getClientOriginalName(); | |
//move the file to correct location | |
$order_number = $request->input('oid'); | |
$username = Auth::user()->username; | |
$path = 'orders/'. $username .'/' . $order_number; | |
if(!file_exists($path)){ | |
mkdir($path, 0777, true); | |
} | |
$file->move($path, $filename); | |
//save the multiple/single file details to database | |
$order = Order::find($request->input('order_id')); | |
$order->images()->create([ | |
'order_id' => $request->input('order_id'), | |
'file_name' => $filename, | |
'file_size' => $file->getClientSize(), | |
'file_mime' => $file->getClientMimeType(), | |
'file_path' => $path . '/' . $filename, | |
]); | |
Session::put('success','Your order has been submitted successfully.'); | |
$data = array( | |
'fullname' => $order->user->fullname, | |
'email' => $order->user->email, | |
'order_number' => $order->order_number | |
); | |
Mail::send('emails.order-submit', $data, function($message) use ($data) { | |
$message->from('[email protected]'); | |
$message->to($data['email']); | |
$message->subject('Order Submit'); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment