Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace App\Http\Controllers; use App\Models\post; use App\Http\Requests\St..
Decoded Output download
<?php
namespace App\Http\Controllers;
use App\Models\post;
use App\Http\Requests\StorepostRequest;
use App\Http\Requests\UpdatepostRequest;
use App\Models\category;
use App\Models\company;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Laravel\Ui\Presets\React;
class PostController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($id = null)
{
if ($id == null || $id == 1) {
$id = 1;
$data = post::where('type_post', $id)->paginate();
return view('admin.post.index', compact('data', 'id'));
} else {
if ($id == 2) {
$data = company::paginate();
return view('admin.post.index', compact('data', 'id'));
} elseif ($id == 3) {
$data = post::where('type_post', 2)->paginate();
return view('admin.post.index', compact('data', 'id'));
}
}
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create($id = null)
{
if ($id == 1 || $id == 2) {
$categories = category::where('parent', null)
->where('type', 1)
->get();
$sub_category = category::where('parent', '!=', null)
->where('type', 1)
->get();
if ($id == 2) {
$categories = category::where('parent', null)
->where('type', 2)
->get();
}
return view('admin.post.create', compact('id', 'categories', 'sub_category', 'id'));
} elseif ($id == 3) {
$categories = category::where('parent', null)
->where('type', 1)
->get();
$sub_category = category::where('parent', '!=', null)
->where('type', 1)
->get();
$companies = company::get();
return view('admin.post.create', compact('id', 'categories', 'sub_category', 'id', 'companies'));
} else {
$id = 1;
$categories = category::where('parent', null)
->where('type', 1)
->get();
$sub_category = category::where('parent', '!=', null)
->get();
return view('admin.post.create', compact('id', 'categories', 'sub_category', 'id'));
}
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\StorepostRequest $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$link = explode('/', $_SERVER['HTTP_REFERER']);
$http = end($link);
$req = $request->all();
$req['type_post'] = $http;
if (!$http) {
$http = 1;
}
if ($http == 2) {
$validation = Validator::make(
$request->all(),
[
'title' => 'required|string',
'status' => 'required|in:1,2',
'sector' => 'exists:sectors,id',
'money.*' => 'required',
'money_value.*' => 'required',
'stock.*' => 'required',
'stock_value.*' => 'required',
'step.*' => 'required',
'step_value.*' => 'required',
'category' => 'required|exists:categories,id'
]
);
$dd = [
'money' => count($request->money),
'money_value' => count($request->money_value),
'stock' => count($request->stock),
'stock_value' => count($request->stock_value),
'step' => count($request->step),
'step_value' => count($request->step_value),
];
if ($validation->fails()) {
return redirect()->back()->withInput()->withErrors($validation->errors())->with($dd);
}
$item = collect();
$item1 = collect();
$item2 = collect();
foreach ($request->money as $key => $money) {
$item = $item->merge(['money_' . $key => $money, 'money_value_' . $key => $request->money_value[$key]]);
}
foreach ($request->stock as $key1 => $stock) {
$item1 = $item1->merge(['stock_' . $key1 => $stock, 'stock_value_' . $key1 => $request->stock_value[$key1]]);
}
foreach ($request->step as $key2 => $step) {
$item2 = $item2->merge(['step_' . $key2 => $step, 'step_value_' . $key2 => $request->step_value[$key2]]);
}
$allItems = $item->merge($item1)
->merge($item2);
$data = [
'title' => $request->title,
'value' => $allItems,
'status' => $request->status,
'user' => user()->id,
'category' => $request->category,
'notes' => $request->notes,
'sector' => $request->sector,
];
company::create($data);
return redirect()->route('posts.index', 2)->with(['success' => ' ']);
} else {
if (is_numeric($request->sub_category) && $request->sub_category !== null) {
$validation = Validator::make(
$req,
[
'title' => 'required|string',
'description' => 'required|string',
'category' => 'required|exists:categories,id',
'sub_category' => 'required|exists:categories,id',
'status' => 'required|in:1,2',
'image' => 'required|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]
);
$sub_category = category::find($request->sub_category);
} else {
$validation = Validator::make(
$req,
[
'title' => 'required|string',
'description' => 'required|string',
'category' => 'required|exists:categories,id',
'sub_category' => 'required|string',
'status' => 'required|in:1,2',
'image' => 'required|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]
);
if (is_string($request->sub_category) && $request->sub_category !== null) {
$addSubCategory = [
'parent' => $request->category,
'title' => $request->sub_category,
'status' => 1,
];
$sub_category = category::create($addSubCategory);
}
}
if ($validation->fails()) {
return redirect()->back()->withInput()->withErrors($validation->errors());
}
if ($request->hasFile('image')) {
$file = $request->file('image');
$image = $file->store('post', [
'disk' => 'public'
]);
$image = url('public/storage/' . $image);
} else {
$image = null;
}
post::create([
'title' => $request->title,
'description' => $request->description,
'image' => $image,
'status' => $request->status,
'type_post' => $http > 1 ? 2 : 1,
'sub_category' => $sub_category->id,
'category' => $request->category,
'company' => $request->company,
'user' => user()->id
]);
if (in_array($http, [1, 2, 3], true)) {
$http = 1;
}
return redirect()->route('posts.index', $http)->with(['success' => ' ']);
}
}
/**
* Display the specified resource.
*
* @param \App\Models\post $post
* @return \Illuminate\Http\Response
*/
public function show(post $post)
{
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\post $post
* @return \Illuminate\Http\Response
*/
public function edit(post $post)
{
$data = $post;
$categories = category::where('parent', null)->get();
if ($post->type_post == 2) {
$categories = category::where('type', 2)->where('parent', null)->get();
$id = 2;
$companies = company::get();
} else {
$id = 1;
$companies = '';
}
$sub_category = category::where('parent', $data->category)->get();
return view('admin.post.edit', compact('data', 'categories', 'id', 'sub_category', 'companies'));
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\UpdatepostRequest $request
* @param \App\Models\post $post
* @return \Illuminate\Http\Response
*/
public function update(Request $request, post $post)
{
if ($request->hasFile('image')) {
$file = $request->file('image');
$image = $file->store('post', [
'disk' => 'public'
]);
$image = url('public/storage/' . $image);
} else {
if ($post->image) {
$image = $post->image;
} else {
$image = null;
}
}
if ($post->type_post == 2) {
if (is_numeric($request->sub_category) && $request->sub_category !== null) {
$validation = Validator::make(
$request->all(),
[
'title' => 'required|string',
'description' => 'required|string',
'category' => 'required|exists:categories,id',
'sub_category' => 'required|exists:categories,id',
'status' => 'required|in:1,2',
'image' => 'nullable|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]
);
$sub_category = category::find($request->sub_category);
} else {
$validation = Validator::make(
$request->all(),
[
'title' => 'required|string',
'description' => 'required|string',
'category' => 'required|exists:categories,id',
'sub_category' => 'required|string',
'status' => 'required|in:1,2',
'image' => 'nullable|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]
);
if (is_string($request->sub_category) && $request->sub_category !== null) {
$addSubCategory = [
'parent' => $request->category,
'title' => $request->sub_category,
'status' => 1,
'type' => 2,
];
$sub_category = category::create($addSubCategory);
}
}
if ($validation->fails()) {
return redirect()->back()->withInput()->withErrors($validation->errors());
}
$data = [
'title' => $request->title,
'description' => $request->description,
'image' => $image,
'status' => $request->status,
'category' => $request->category,
'sub_category' => $sub_category->id,
'user' => user()->id,
];
post::where('id', $post->id)->update($data);
return redirect()->route('posts.index', 3)->with(['success' => ' ']);
} else {
$validation = Validator::make(
$request->all(),
[
'title' => 'required|string',
'description' => 'required|string',
'category' => 'required|exists:categories,id',
'sub_category' => 'required|exists:categories,id',
'status' => 'required|in:1,2',
'image' => 'nullable|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]
);
if ($validation->fails()) {
return redirect()->back()->withInput()->withErrors($validation->errors());
}
$data = [
'title' => $request->title,
'description' => $request->description,
'image' => $image,
'status' => $request->status,
'category' => $request->category,
'sub_category' => $request->sub_category,
'user' => user()->id,
];
post::where('id', $post->id)->update($data);
return redirect()->route('posts.index')->with(['success' => ' ']);
}
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\post $post
* @return \Illuminate\Http\Response
*/
public function destroy(post $post)
{
$post->deleted_by = user()->id;
$post->save();
$post->delete();
$type_post = $post->type_post == 1 ? '' : ' / ';
return redirect()->back()->with(['success' => " $type_post "]);
}
public function upload(Request $request)
{
$fileName = $request->file('file')->getClientOriginalName();
$path = $request->file('file')->storeAs('uploads', $fileName, 'public');
return response()->json(['location' => url("/public/storage/$path")]);
}
}
?>
Did this file decode correctly?
Original Code
<?php
namespace App\Http\Controllers;
use App\Models\post;
use App\Http\Requests\StorepostRequest;
use App\Http\Requests\UpdatepostRequest;
use App\Models\category;
use App\Models\company;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Laravel\Ui\Presets\React;
class PostController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($id = null)
{
if ($id == null || $id == 1) {
$id = 1;
$data = post::where('type_post', $id)->paginate();
return view('admin.post.index', compact('data', 'id'));
} else {
if ($id == 2) {
$data = company::paginate();
return view('admin.post.index', compact('data', 'id'));
} elseif ($id == 3) {
$data = post::where('type_post', 2)->paginate();
return view('admin.post.index', compact('data', 'id'));
}
}
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create($id = null)
{
if ($id == 1 || $id == 2) {
$categories = category::where('parent', null)
->where('type', 1)
->get();
$sub_category = category::where('parent', '!=', null)
->where('type', 1)
->get();
if ($id == 2) {
$categories = category::where('parent', null)
->where('type', 2)
->get();
}
return view('admin.post.create', compact('id', 'categories', 'sub_category', 'id'));
} elseif ($id == 3) {
$categories = category::where('parent', null)
->where('type', 1)
->get();
$sub_category = category::where('parent', '!=', null)
->where('type', 1)
->get();
$companies = company::get();
return view('admin.post.create', compact('id', 'categories', 'sub_category', 'id', 'companies'));
} else {
$id = 1;
$categories = category::where('parent', null)
->where('type', 1)
->get();
$sub_category = category::where('parent', '!=', null)
->get();
return view('admin.post.create', compact('id', 'categories', 'sub_category', 'id'));
}
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\StorepostRequest $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$link = explode('/', $_SERVER['HTTP_REFERER']);
$http = end($link);
$req = $request->all();
$req['type_post'] = $http;
if (!$http) {
$http = 1;
}
if ($http == 2) {
$validation = Validator::make(
$request->all(),
[
'title' => 'required|string',
'status' => 'required|in:1,2',
'sector' => 'exists:sectors,id',
'money.*' => 'required',
'money_value.*' => 'required',
'stock.*' => 'required',
'stock_value.*' => 'required',
'step.*' => 'required',
'step_value.*' => 'required',
'category' => 'required|exists:categories,id'
]
);
$dd = [
'money' => count($request->money),
'money_value' => count($request->money_value),
'stock' => count($request->stock),
'stock_value' => count($request->stock_value),
'step' => count($request->step),
'step_value' => count($request->step_value),
];
if ($validation->fails()) {
return redirect()->back()->withInput()->withErrors($validation->errors())->with($dd);
}
$item = collect();
$item1 = collect();
$item2 = collect();
foreach ($request->money as $key => $money) {
$item = $item->merge(['money_' . $key => $money, 'money_value_' . $key => $request->money_value[$key]]);
}
foreach ($request->stock as $key1 => $stock) {
$item1 = $item1->merge(['stock_' . $key1 => $stock, 'stock_value_' . $key1 => $request->stock_value[$key1]]);
}
foreach ($request->step as $key2 => $step) {
$item2 = $item2->merge(['step_' . $key2 => $step, 'step_value_' . $key2 => $request->step_value[$key2]]);
}
$allItems = $item->merge($item1)
->merge($item2);
$data = [
'title' => $request->title,
'value' => $allItems,
'status' => $request->status,
'user' => user()->id,
'category' => $request->category,
'notes' => $request->notes,
'sector' => $request->sector,
];
company::create($data);
return redirect()->route('posts.index', 2)->with(['success' => ' ']);
} else {
if (is_numeric($request->sub_category) && $request->sub_category !== null) {
$validation = Validator::make(
$req,
[
'title' => 'required|string',
'description' => 'required|string',
'category' => 'required|exists:categories,id',
'sub_category' => 'required|exists:categories,id',
'status' => 'required|in:1,2',
'image' => 'required|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]
);
$sub_category = category::find($request->sub_category);
} else {
$validation = Validator::make(
$req,
[
'title' => 'required|string',
'description' => 'required|string',
'category' => 'required|exists:categories,id',
'sub_category' => 'required|string',
'status' => 'required|in:1,2',
'image' => 'required|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]
);
if (is_string($request->sub_category) && $request->sub_category !== null) {
$addSubCategory = [
'parent' => $request->category,
'title' => $request->sub_category,
'status' => 1,
];
$sub_category = category::create($addSubCategory);
}
}
if ($validation->fails()) {
return redirect()->back()->withInput()->withErrors($validation->errors());
}
if ($request->hasFile('image')) {
$file = $request->file('image');
$image = $file->store('post', [
'disk' => 'public'
]);
$image = url('public/storage/' . $image);
} else {
$image = null;
}
post::create([
'title' => $request->title,
'description' => $request->description,
'image' => $image,
'status' => $request->status,
'type_post' => $http > 1 ? 2 : 1,
'sub_category' => $sub_category->id,
'category' => $request->category,
'company' => $request->company,
'user' => user()->id
]);
if (in_array($http, [1, 2, 3], true)) {
$http = 1;
}
return redirect()->route('posts.index', $http)->with(['success' => ' ']);
}
}
/**
* Display the specified resource.
*
* @param \App\Models\post $post
* @return \Illuminate\Http\Response
*/
public function show(post $post)
{
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\post $post
* @return \Illuminate\Http\Response
*/
public function edit(post $post)
{
$data = $post;
$categories = category::where('parent', null)->get();
if ($post->type_post == 2) {
$categories = category::where('type', 2)->where('parent', null)->get();
$id = 2;
$companies = company::get();
} else {
$id = 1;
$companies = '';
}
$sub_category = category::where('parent', $data->category)->get();
return view('admin.post.edit', compact('data', 'categories', 'id', 'sub_category', 'companies'));
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\UpdatepostRequest $request
* @param \App\Models\post $post
* @return \Illuminate\Http\Response
*/
public function update(Request $request, post $post)
{
if ($request->hasFile('image')) {
$file = $request->file('image');
$image = $file->store('post', [
'disk' => 'public'
]);
$image = url('public/storage/' . $image);
} else {
if ($post->image) {
$image = $post->image;
} else {
$image = null;
}
}
if ($post->type_post == 2) {
if (is_numeric($request->sub_category) && $request->sub_category !== null) {
$validation = Validator::make(
$request->all(),
[
'title' => 'required|string',
'description' => 'required|string',
'category' => 'required|exists:categories,id',
'sub_category' => 'required|exists:categories,id',
'status' => 'required|in:1,2',
'image' => 'nullable|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]
);
$sub_category = category::find($request->sub_category);
} else {
$validation = Validator::make(
$request->all(),
[
'title' => 'required|string',
'description' => 'required|string',
'category' => 'required|exists:categories,id',
'sub_category' => 'required|string',
'status' => 'required|in:1,2',
'image' => 'nullable|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]
);
if (is_string($request->sub_category) && $request->sub_category !== null) {
$addSubCategory = [
'parent' => $request->category,
'title' => $request->sub_category,
'status' => 1,
'type' => 2,
];
$sub_category = category::create($addSubCategory);
}
}
if ($validation->fails()) {
return redirect()->back()->withInput()->withErrors($validation->errors());
}
$data = [
'title' => $request->title,
'description' => $request->description,
'image' => $image,
'status' => $request->status,
'category' => $request->category,
'sub_category' => $sub_category->id,
'user' => user()->id,
];
post::where('id', $post->id)->update($data);
return redirect()->route('posts.index', 3)->with(['success' => ' ']);
} else {
$validation = Validator::make(
$request->all(),
[
'title' => 'required|string',
'description' => 'required|string',
'category' => 'required|exists:categories,id',
'sub_category' => 'required|exists:categories,id',
'status' => 'required|in:1,2',
'image' => 'nullable|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]
);
if ($validation->fails()) {
return redirect()->back()->withInput()->withErrors($validation->errors());
}
$data = [
'title' => $request->title,
'description' => $request->description,
'image' => $image,
'status' => $request->status,
'category' => $request->category,
'sub_category' => $request->sub_category,
'user' => user()->id,
];
post::where('id', $post->id)->update($data);
return redirect()->route('posts.index')->with(['success' => ' ']);
}
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\post $post
* @return \Illuminate\Http\Response
*/
public function destroy(post $post)
{
$post->deleted_by = user()->id;
$post->save();
$post->delete();
$type_post = $post->type_post == 1 ? '' : ' / ';
return redirect()->back()->with(['success' => " $type_post "]);
}
public function upload(Request $request)
{
$fileName = $request->file('file')->getClientOriginalName();
$path = $request->file('file')->storeAs('uploads', $fileName, 'public');
return response()->json(['location' => url("/public/storage/$path")]);
}
}
Function Calls
None |
Stats
MD5 | 97e10f8a816a4dd1c684b36225a63ad5 |
Eval Count | 0 |
Decode Time | 93 ms |