Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

48 lines
1.4 KiB

<?php
namespace App\Http\Controllers;
use App\SearchDisplace\Documents\DocumentFile;
use App\SearchDisplace\SearchAndDisplace;
class SearchAndDisplaceController extends Controller
{
public function show($id)
{
$handler = new DocumentFile();
try {
$documentContent = $handler->getAfterIngest($id);
return response()->json([
'content' => $documentContent,
'ingest_status' => !! $documentContent ? 'success' : 'fail',
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => $exception->getMessage(),
], 400);
}
}
public function store()
{
request()->validate([
'content' => 'required', // String or file.
'searchers' => 'required|array', // Check if matches all rules, must have 'key' and 'replace_with'.
]);
$searchAndDisplace = new SearchAndDisplace(request()->input('content'), [
'searchers' => request()->input('searchers'),
]);
try {
return response()->json($searchAndDisplace->execute(), 200);
} catch (\Exception $exception) {
return response()->json([
'message' => $exception->getMessage(),
'trace' => $exception->getTrace(),
], 400);
}
}
}